vinyll / django-imagefit

Resize an image on render. Preserve your original file on your system.
BSD 3-Clause "New" or "Revised" License
84 stars 40 forks source link

EXIF rotation information lost #11

Open laurivosandi opened 8 years ago

laurivosandi commented 8 years ago

Hi,

it seems JPEG images with EXIF rotation info are messed up after resizing. This can be easily fixed by rotating the image after resizing based on the information found in EXIF tags:

try:
    from exifread import process_file # This is for newer Ubuntus
except ImportError:
    from EXIF import process_file # This is for Ubuntu 14.04

tags = process_file(open("path/to/filename.jpg"))
orientation = tags.get("Image Orientation")

if orientation:
    j, = orientation.values
    if j == 6:
        print "rotated 270 degrees"
    elif j == 8:
        print "rotated 90 degrees"
    elif j == 3:
        print "rotated 180 degrees"

Also to speed up resizing/rotation you could take a look at epeg at https://github.com/mattes/epeg

vinyll commented 6 years ago

Hey @laurivosandi! It's been a while you reported this issue but I couldn't understand it. I might start to comprehend your point here. Probably you've been over it, but your knowledge may be useful here.

Do you think this issue on Neomad and this one from the Medium Editor Plugin could be also for the same reason?

laurivosandi commented 6 years ago

Hi, yes this looks exactly like the same issue

laurivosandi commented 6 years ago

The point is JPEG data orientation doesn't have to match the orientation it is supposed to be shown in. EXIF tags show you the intended orientation.

vinyll commented 6 years ago

Some hint based on the current library used in Imagefit: https://stackoverflow.com/a/6218425/328117 This seems simple enough to be implemented.

vinyll commented 6 years ago

Wondering if we should reorient the picture or just pass EXIF metadata. I was working on the first option, but second might make more sense as it preserves a little more the original data.

Any opinion @laurivosandi ?