Python Program to Find the Size (Resolution) of Image

By | October 3, 2021
Python Program to Find the Size (Resolution) of Image

Here in this article, we have provided two different python source codes which can find the resolution of a jpeg image.

Prerequisite topics to create this program.

  • Python Function
  • Python File handling.
  • Python PIL library
  • Python user-defined function
  • Python file I/O

Find the Size (Resolution) of a JPEG Image Without any External Library:


def image_resolution(filename):

   # open image in binary mode
   with open(filename,'rb') as img:

       # height of image (in 2 bytes) is at 164th position

       # read the 2 bytes
       x =

       # calculate height
       height = (x[0] << 8) +x[1]

       # next 2 bytes is width
       x =

       # calculate width
       width = (x[0] << 8) + x[1]

   print("Width X Height: ", width,"X",height)



Width X Height: 57601 X 255

Find the Size (Resolution) of Image With PIL Library:


use pip install PIL command to install the PIL library:


from PIL import Image
image = "Image.jpg"
img =
width, height = img.size
print("The image resolution  is", width, "x", height)


The image resolution is 1333 x 1000

People are also reading:

Author: Vinay

I am a Full Stack Developer with a Bachelor's Degree in Computer Science, who also loves to write technical articles that can help fellow developers.

Leave a Reply

Your email address will not be published.