Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#5525 closed defect (fixed)

EXIF rotation is not detected

Reported by: chrysn Owned by:
Priority: major Milestone:
Component: programming Keywords:
Cc: Parent Tickets:

Description

With images created by a Nikon D7200 v1.02, EXIF rotation is not detected. As a result, both the thumbnail and the regular view are cropped to the center square of the image and have black bars left and right of it. Zooming in (ie. loading the original image) in the browser shows correctly (probably because the browser parses the rotation itself).

If I create a .png that is externally rotated and upload that, everything looks fine, but with the camera JPGs, I get the described effect.

exiftool shows "Orientation: Rotate 270 CW" for the image; if there is any more detailed information I can extract from the image, please let me know.

Attachments (1)

0001-Fix-EXIF-rotation-to-make-the-image-portrait-on-dema.patch (1.4 KB ) - added by chrysn 7 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 by chrysn, 7 years ago

The im.rotate function does not resize the image, it just applies arbitrary-angle rotation. The transpose function does the right thing, a patch is attached. (I wonder how this has ever worked at all).

comment:2 by ayleph, 6 years ago

Status: newaccepted

Hi chrysn, thanks for the patch. I haven't been able to replicate the issue with any of my own camera's images. Could you possibly provide an affected image for testing?

comment:3 by chrysn, 6 years ago

None I can easily make public, but if you mail me at chrysn@…, I can send you an image directly -- or you try <http://duckz.serveblog.net/risorse/foto/francia/P1831_21-02-10.jpg>, which I didn't test on mediagoblin (removed my installation again), but behaves the same in PIL.

What I just did to verify it behaves the same under the minimal rotate() example below. If the provided test image rotates correctly in your MG and in the code below, we're looking at different implementations (versions? Can't imagine.) of PIL. (I tested it on Python 2.7 and 3.6 with PIL 4.3.0 (through the Imaging compatibility layer in Python 2.7)). If it rotates correctly in your MG but not in the code below, I'd say that your MG is taking a different code path, and not through the patched area (due to other installed tools maybe?).

try:
    from PIL import Image
except ImportError:
    import Image

i = Image.open('./P1831_21-02-10.jpg')
i = i.rotate(270)
i.save('out.png')

comment:4 by ayleph, 6 years ago

Resolution: fixed
Status: acceptedclosed

Thanks for providing a test image. With that image, I was able to reproduce the issue that you reported. I tested your patch and found that it resolves this issue and that our exif tests still pass. I also tested a simpler fix of just adding expand=True to the im.rotate command. This fixed the reported issue, but it also resulted in a slightly weird image size as noted here.

Your patch appears to be the correct solution to this problem. I have merged this to master in 98340b6. Thank you very much for investing this issue and submitting a patch. Is there a name you would like me to use to add you to the AUTHORS file?

comment:5 by chrysn, 6 years ago

If that a small patch qualifies and you don't insist on having passport-issued names, I'll go by chrysn as in most Free Software I write; thanks.

comment:6 by ayleph, 6 years ago

Got it. Thanks again!

Note: See TracTickets for help on using tickets.