MCPcopy Create free account
hub / github.com/geekcomputers/Python / jpeg_res

Function jpeg_res

size(resolution)image.py:1–21  ·  view source on GitHub ↗

"This function prints the resolution of the jpeg image file passed into it

(filename)

Source from the content-addressed store, hash-verified

1def 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 # height of image (in 2 bytes) is at 164th position
7 img_file.seek(163)
8
9 # read the 2 bytes
10 a = img_file.read(2)
11
12 # calculate height
13 height = (a[0] << 8) + a[1]
14
15 # next 2 bytes is width
16 a = img_file.read(2)
17
18 # calculate width
19 width = (a[0] << 8) + a[1]
20
21 print("The resolution of the image is", width, "x", height)
22
23
24jpeg_res("img1.jpg")

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected