Write a python Program to Find the Size (Resolution) of a JPEG Image and print it


Topic: Write a python Program to Find the Size (Resolution) of a JPEG Image and print it

Solution

def jpeg_res(filename):
   with open(filename,'rb') as img_file:
       img_file.seek(163)
       a = img_file.read(2)
       # calculate height
       height = (a[0] << 8) + a[1]
       # next 2 bytes is width
       a = img_file.read(2)
       # calculate width
       width = (a[0] << 8) + a[1]
   print("The resolution of the image is",width,"x",height)



List all Python Programs