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%
🌐
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
Discussions

pysimplegui - How to display images in python simple gui from a api url - Stack Overflow
I want to read a image from api, but I am getting a error TypeError: 'module' object is not callable. I am trying to make a random meme generator import PySimpleGUI as sg from PIL import Image imp... More on stackoverflow.com
🌐 stackoverflow.com
Python Rest API POST an image - Stack Overflow
Below is my code. I am trying to make a POST operation using python with REST API. I have an image I want to post. I get error saying; "'code': 'BadRequest', 'message': "Could not process incoming More on stackoverflow.com
🌐 stackoverflow.com
December 20, 2018
Download images api python - Stack Overflow
I have a simple code What I want is to download the images from the api, but it doesn't download them import requests url = "https://www.habbo.es/extradata/public/users/hhes- More on stackoverflow.com
🌐 stackoverflow.com
June 13, 2022
How to upload images as attachment via API with Python?
Self-explanatory title 🙂 I have URLs for images that I would like to attach in the Grist records (not just the URL of it). Seems I’m missing a trick here and couldn’t find anything searching this forum. Using python3 with the grist_api library. Thanks for your help! More on community.getgrist.com
🌐 community.getgrist.com
0
0
July 23, 2022
🌐
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

🌐
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 ·
Find elsewhere
🌐
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.
🌐
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
🌐
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).
🌐
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.
🌐
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.
🌐
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.
🌐
Pillow
pillow.readthedocs.io
Pillow (PIL Fork) 12.2.0 documentation
The Python Imaging Library adds image processing capabilities to your Python interpreter.
🌐
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 ·
🌐
Grist Creators
community.getgrist.com › ask for help
How to upload images as attachment via API with Python? - Ask for Help - Grist Creators
July 23, 2022 - Self-explanatory title :slight_smile: I have URLs for images that I would like to attach in the Grist records (not just the URL of it). Seems I’m missing a trick here and couldn’t find anything searching this forum. U…
🌐
OpenAI
platform.openai.com › docs › guides › images-vision
Images and vision | OpenAI API
Analyze the content of an image · python · 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 import OpenAI from "openai"; import fs from "fs"; const openai = new OpenAI(); // Function to create a file with the Files API async function createFile(filePath) { const fileContent = fs.createReadStream(filePath); const result = await openai.files.create({ file: fileContent, purpose: "vision", }); return result.id; } // Getting the file ID const fileId = await createFile("path_to_your_image.jpg"); const response = await openai.responses.create({ model: "gpt-4.1-mini", input: [ { role: "user", content: [ { type: "input_text", text: "what's in this image?"