Last modified: Jul 02, 2023 By Alexander Williams

Python: Get Image Size From URL Using Requests

In this guide, we'll use the requests library to retrieve image size from an image URL.

Requests Installation

Run the following command to install requests:

pip install requests

Get Image Size From URL

The following example demonstrates how to get the image size from a given URL:

import requests

# Send an HTTP GET request to fetch the image content
req = requests.get('https://pytutorial.com/theme/img/articles_image/py.jpg')

# Extract the content of the image from the response
img_content = req.content

# Print the length of the image content in bytes
print(len(img_content))

Output:

87895 bytes

As you can see, we got the size in bytes. If you want to convert it to human-readable formats, this article hurry Filesize in Python will be useful.