-
Normally, getting the Is there any fast way to get the dimensions of an image that takes the exif orientation into account but doesn't load the image data? |
Beta Was this translation helpful? Give feedback.
Answered by
radarhere
Jul 30, 2025
Replies: 1 comment 5 replies
-
Hi. My suggestion would be from PIL import ExifTags
def get_size_with_exif_orientation_applied(im):
size = im.size
if im.getexif().get(ExifTags.Base.Orientation) in (5, 6, 7, 8):
size = (im.height, im.width)
return size |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
While I expect this will work for you on a practical level, on a theoretical level, I don't think we can guarantee that it will be correct without first loading the image - PNG images may contain
tEXT
chunks after the image data, and thosetEXT
chunks may contain EXIF data.