From 8aabff18993ecf3e59a000d5b957a8853d61c528 Mon Sep 17 00:00:00 2001 From: Prashant Pandey <67793059+lemihack@users.noreply.github.com> Date: Mon, 25 Oct 2021 11:01:13 +0545 Subject: [PATCH] Create px-size.py --- Pythons/px-size.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Pythons/px-size.py diff --git a/Pythons/px-size.py b/Pythons/px-size.py new file mode 100644 index 0000000..9c6336d --- /dev/null +++ b/Pythons/px-size.py @@ -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")