PIL.Image is a module, you can not call it by Image(...), maybe you need call it by Image.open(...). At the same, tkinter/PySimpleGUI cannot handle JPG image, so conversion to PNG image is required.

from io import BytesIO
import PySimpleGUI as sg
from PIL import Image
import requests, json

def image_to_data(im):
    """
    Image object to bytes object.
    : Parameters
      im - Image object
    : Return
      bytes object.
    """
    with BytesIO() as output:
        im.save(output, format="PNG")
        data = output.getvalue()
    return data

cutURL = 'https://meme-api-python.herokuapp.com/gimme'

imageURL = json.loads(requests.get(cutURL).content)["url"]
data = requests.get(imageURL).content
stream = BytesIO(data)
img = Image.open(stream)

img_box = sg.Image(image_to_data(img))

window = sg.Window('', [[img_box]], finalize=True)

# Check if the size of the window is greater than the screen
w1, h1 = window.size
w2, h2 = sg.Window.get_screen_size()
if w1>w2 or h1>h2:
    window.move(0, 0)

while True:
    event, values = window.read()
    if event is None:
        break
window.close()
Answer from Jason Yang on Stack Overflow
🌐
GitHub
github.com › gxercavins › image-api
GitHub - gxercavins/image-api: Image Processing API using Python + Flask + PIL
Image Processing API written in Python, using the Pillow library for image manipulation and exposing the functions with the Flask framework.
Starred by 76 users
Forked by 21 users
Languages   Python 60.6% | HTML 30.5% | CSS 8.9% | Python 60.6% | HTML 30.5% | CSS 8.9%
🌐
Reddit
reddit.com › r/python › introducing an open-source python api for ai image generator midjourney
r/Python on Reddit: Introducing an Open-Source Python API for AI Image Generator Midjourney
May 28, 2023 -

Hi r/Python, I've created an open-source Python API for Midjourney, a tool that generates AI images. Previously, this was only possible within a Discord server, but now you can do it directly from your Python scripts! I'd love for you to check it out and share your thoughts: https://github.com/yachty66/unofficial_midjourney_python_api

🌐
PyPI
pypi.org › project › Google-Images-Search
Google-Images-Search · PyPI
from google_images_search import GoogleImagesSearch # you can provide API key and CX using arguments, # or you can set environment variables: GCS_DEVELOPER_KEY, GCS_CX gis = GoogleImagesSearch('your_dev_api_key', 'your_project_cx') # define search params # option for commonly used search param are shown below for easy reference.
      » pip install Google-Images-Search
    
Published   Jul 03, 2024
Version   1.4.7
🌐
Transloadit
transloadit.com › devtips › creating-a-simple-image-processing-api-with-python-and-flask
Creating a simple image processing API with Python and Flask | Transloadit
February 5, 2025 - # Resize an image curl -fsSL -X POST -F "file=@path/to/image.jpg" -F "width=300" -F "height=200" \ http://localhost:5000/resize -o resized_image.jpg # Convert an image to PNG curl -fsSL -X POST -F "file=@path/to/image.jpg" -F "format=PNG" \ http://localhost:5000/convert -o converted_image.png · For production, comprehensive testing is essential. Create a file named test_app.py with the following tests to validate the API's functionality:
🌐
Wikimedia
api.wikimedia.org › wiki › Reusing_free_images_and_media_files_with_Python
Reusing free images and media files with Python - API Portal
import requests file = 'File:The_Blue_Marble.jpg' headers = { # 'Authorization': 'Bearer YOUR_ACCESS_TOKEN', 'User-Agent': 'YOUR_APP_NAME (YOUR_EMAIL_OR_CONTACT_PAGE)' } base_url = 'https://api.wikimedia.org/core/v1/commons/file/' url = base_url + file response = requests.get(url, headers=headers) Once you've made the request, you can extract the image's preferred format from the JSON response. On the file description page, you can see that File:The_Blue_Marble.jpg is in the public domain. To provide attribution for the image, include the license, and link back to the file page.
Top answer
1 of 3
3

PIL.Image is a module, you can not call it by Image(...), maybe you need call it by Image.open(...). At the same, tkinter/PySimpleGUI cannot handle JPG image, so conversion to PNG image is required.

from io import BytesIO
import PySimpleGUI as sg
from PIL import Image
import requests, json

def image_to_data(im):
    """
    Image object to bytes object.
    : Parameters
      im - Image object
    : Return
      bytes object.
    """
    with BytesIO() as output:
        im.save(output, format="PNG")
        data = output.getvalue()
    return data

cutURL = 'https://meme-api-python.herokuapp.com/gimme'

imageURL = json.loads(requests.get(cutURL).content)["url"]
data = requests.get(imageURL).content
stream = BytesIO(data)
img = Image.open(stream)

img_box = sg.Image(image_to_data(img))

window = sg.Window('', [[img_box]], finalize=True)

# Check if the size of the window is greater than the screen
w1, h1 = window.size
w2, h2 = sg.Window.get_screen_size()
if w1>w2 or h1>h2:
    window.move(0, 0)

while True:
    event, values = window.read()
    if event is None:
        break
window.close()
2 of 3
2

You need to use Image.open(...) - Image is a module, not a class. You can find a tutorial in the official PIL documentation.

You may need to put the response content in a BytesIO object before you can use Image.open on it. BytesIO is a file-like object that exists only in memory. Most functions like Image.open that expect a file-like object will also accept BytesIO and StringIO (the text equivalent) objects.

Example:

from io import BytesIO

def get_image(url):
    data = BytesIO(requests.get(url).content)
    return Image.open(data)
🌐
OpenAI
platform.openai.com › docs › guides › image-generation
Image generation | OpenAI API
With the Responses API you can choose whether to generate a new image or edit one already in the conversation. The optional action parameter (supported on gpt-image-1.5 and chatgpt-image-latest) controls this behavior: keep action: "auto" to let the model decide (recommended), set action: "generate" to always create a new image, or set action: "edit" to force editing (requires an image in context). Force image creation with action · python ·
🌐
Wlu
lambertk.academic.wlu.edu › publications › python-programming › fundamentals-of-python › the-images-api
The images API - Ken Lambert - Washington and Lee University
The images module includes a single class named Image. Each Image object represents an image. The programmer can supply the file name of an image on disk when Image is instantiated. The resulting Image object contains pixels loaded from an image file on disk.
Find elsewhere
🌐
Medium
medium.com › @giacomo.piccinini › building-your-own-free-api-for-generating-python-snippet-images-a-step-by-step-guide-593430eb0a86
Building Your Own Free API for Generating Python Snippet Images: A Step-by-Step Guide | by Giacomo Piccinini | Medium
September 4, 2023 - So, I thought it would be cool and informative to create my own API. In this tutorial, I’ll walk you through the process of building and deploying (for real!) your own Python snippet image generator API using Modal and Flask, empowering you to showcase your code in style without breaking the bank.
🌐
GeeksforGeeks
geeksforgeeks.org › data science › generate-images-with-openai-in-python
Generate Images With OpenAI in Python - GeeksforGeeks
Using DALL - E API we are able to generate and edit images using Python code.
Published   July 23, 2025
🌐
Apify
apify.com › easyapi › unsplash-image-scraper › api › python
Unsplash Image Scraper API in Python · Apify
December 6, 2024 - The Apify API client for Python is the official library that allows you to use Unsplash Image Scraper API in Python, providing convenience functions and automatic retries on errors.
🌐
ProxiesAPI
proxiesapi.com › articles › uploading-images-with-python-requests
Uploading Images with Python Requests | ProxiesAPI
POST request object. Set the URL to upload the image to and add any headers or other parameters: ... url = "https://api.example.com/image-upload" headers = {"Authorization": "Client-ID xxx"} r = requests.post(url, headers=headers)
🌐
Blender
docs.blender.org › api › current › bpy.types.Image.html
Image(ID) - Blender Python API
The Image data-block is a shallow wrapper around image or video file(s) (on disk, as packed data, or generated).
🌐
GitHub
github.com › topics › image-api
image-api · GitHub Topics · GitHub
api gallery img image-api image-hosting img-api gallery-api ... vehicles API with our cutting-edge API built on FastAPI, the lightning-fast Python web framework, and backed by the robustness of AWS DynamoDB, the fully managed NoSQL database service.
🌐
Real Python
realpython.com › generate-images-with-dalle-openai-api
Generate Images With DALL·E and the OpenAI API – Real Python
September 2, 2024 - Learn to use the OpenAI Python library to create images with DALL·E, a state-of-the-art latent diffusion model. In this tutorial, you'll explore creating images and generating image variations.
🌐
scikit-image
scikit-image.org
scikit-image: Image processing in Python — scikit-image
The scikit-image team is hard at work at bringing you scikit-image v2, a major overhaul with a cleaner and more intuitive API. We would like to thank our project sponsors, ... Reach out if you would like to join them in supporting the next generation of open source image processing in Python.
🌐
Apify
apify.com › igview-owner › image-resizer-api › api › python
Resize image API API in Python · Apify
November 22, 2025 - The Apify API client for Python is the official library that allows you to use Image Resizer API API in Python, providing convenience functions and automatic retries on errors.
🌐
SheCodes
shecodes.io › athena › 1950-free-image-databases-api-with-python
[Python] - Free Image Databases API with Python - SheCodes | SheCodes
Find out the available free image databases API's like Pixabay and Flickr. Learn more about their features and which programming languages are supported. Asked almost 3 years ago in Python by Oksana · free image databases api · image databases API Pixabay Flickr ·