with open("image.jpg",'rb') as file:
file.seek(163)
a = file.read(2)
height = (a[0] << 8) - a[1]
a = file.read(2)
width = (a[0] << 8) - a[1]
print(str(height) + " x " + str(width))
I am still learning python. I know bitwise operators leftshift and rightshift. But I don't understand this code.
What I understand is:
- We open the image with binary reading as file.
- Move the cursor to 163 with
file.seek(). Why 163? - Read the file with size of 2 bytes. Why?
I don't understand the 4th line and 6th line at all. Print function is okay.
I tried with Pillow and cv2. But in case, I can't work with those modules, I think I should know this one.