Skip to content

Commit 8eb6884

Browse files
author
codehouseindia
authored
Merge pull request codehouseindia#540 from baishakhi9931/patch-7
Create resolution.py
2 parents 2290692 + 7e18d22 commit 8eb6884

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

resolution.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
def jpeg_res(filename):
2+
""""This function prints the resolution of the jpeg image file passed into it"""
3+
4+
# open image for reading in binary mode
5+
with open(filename,'rb') as img_file:
6+
7+
# height of image (in 2 bytes) is at 164th position
8+
img_file.seek(163)
9+
10+
# read the 2 bytes
11+
a = img_file.read(2)
12+
13+
# calculate height
14+
height = (a[0] << 8) + a[1]
15+
16+
# next 2 bytes is width
17+
a = img_file.read(2)
18+
19+
# calculate width
20+
width = (a[0] << 8) + a[1]
21+
22+
print("The resolution of the image is",width,"x",height)
23+
24+
jpeg_res("img1.jpg")

0 commit comments

Comments
 (0)