shibukawa / imagesize_py

MIT License
222 stars 43 forks source link

Width and height of image are transposed when EXIF contains rotation metadata #61

Open Gilthans opened 1 year ago

Gilthans commented 1 year ago

EXIF supports 'Orientation' parameter, which may instruct the image to be opened after rotating by 90 degrees. This is respected by all software I have tested, but unfortunately not by imagesize, causing incorrect results.

Sample image: example-exif Same image with orientation EXIF set to rotate 90 degrees CW: example-exif-rotated

However, when I run the following code:

print(imagesize.get('example-exif.jpg')) # This prints (300, 100)
print(imagesize.get('example-exif-rotated.jpg')) # This prints (300, 100)

# Note that numpy image dimensions are (height, width, colors)
print(imageio.imread('example-exif-rotated.jpg').shape) # This prints (100, 300, 3)
print(imageio.imread('example-exif-rotated.jpg').shape) # This prints (300, 100, 3)