From b5dc8d6ffc3f66aed294a71fb3af2835f3aa0646 Mon Sep 17 00:00:00 2001 From: Chetanverma93 <66515815+Chetanverma93@users.noreply.github.com> Date: Sat, 3 Oct 2020 12:45:34 +0530 Subject: [PATCH] Create Find resolution of jpeg image Generate python code for find resolution of image --- Find resolution of jpeg image | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Find resolution of jpeg image diff --git a/Find resolution of jpeg image b/Find resolution of jpeg image new file mode 100644 index 0000000..9c6336d --- /dev/null +++ b/Find resolution of jpeg image @@ -0,0 +1,24 @@ +def jpeg_res(filename): + """"This function prints the resolution of the jpeg image file passed into it""" + + # open image for reading in binary mode + with open(filename,'rb') as img_file: + + # height of image (in 2 bytes) is at 164th position + img_file.seek(163) + + # read the 2 bytes + 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) + +jpeg_res("img1.jpg")