"This function prints the resolution of the jpeg image file passed into it
(filename)
| 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 | # 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 | |
| 24 | jpeg_res("img1.jpg") |
no outgoing calls
no test coverage detected