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.
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:
# 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
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.