Python Program to Find the Size (Resolution) of a Image


10xer.co Ad Sponsored

ⓘ Sponsored by 10xer.co

Resolution of an image refers to the number of pixels or dots that make up the image, typically expressed as a measurement of the width and height in pixels. In digital images, resolution is often used to describe the quality and clarity of the image, with higher resolution images generally being sharper and more detailed.


Python Code :

To find the size or resolution of an image in Python, you can use the Pillow library. Pillow is a popular Python library for image processing and provides a simple and efficient way to perform various image manipulation tasks.

Here’s a Python program that finds the size (resolution) of an image using the Pillow library:


from PIL import Image

# Open the image file
image = Image.open('image.jpg')

# Get the size of the image
width, height = image.size

# Print the size of the image
print(f"The size of the image is: {width} x {height}")

In this program, we first import the Image class from the PIL library. We then open the image file using the Image.open() method and assign it to the image variable.

Next, we use the size attribute of the Image class to get the width and height of the image and assign them to the width and height variables.

Finally, we print the size of the image using the print() function and f-strings to format the output.

Note that you need to install the Pillow library before running this program. You can do this by running the following command in your terminal or command prompt:


pip install Pillow

Make sure that you replace image.jpg with the actual filename and extension of the image you want to find the size of.


10xer.co Ad Sponsored

ⓘ Sponsored by 10xer.co