New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autorotate gallery images #72

Open
reagle opened this Issue Feb 4, 2014 · 21 comments

Comments

3 participants
@reagle

reagle commented Feb 4, 2014

sigal seems smart enough to orient portrait images when it is within its own HTML framing. However, the actual jpgs (thumbnail and gallery images) are not rotated. I'd prefer the actual images be rotated so that if I want to use the image or thumbnail elsewhere on my website, it's in the correct orientation.

@saimn

This comment has been minimized.

Owner

saimn commented Feb 5, 2014

The rotation is done by pilkit:
https://github.com/saimn/sigal/blob/master/sigal/image.py#L77
https://github.com/matthewwithanm/pilkit/blob/master/pilkit/processors/base.py#L113

But there may be an issue with the copy_exif_data setting which copy the original exif (with the unmodified orientation tag). To confirm this, could you try with copy_exif_data = False ?

@reagle

This comment has been minimized.

reagle commented Feb 12, 2014

Related to firefox not rotating the image: https://bugzilla.mozilla.org/show_bug.cgi?id=298619

@reagle

This comment has been minimized.

reagle commented Feb 12, 2014

Okay, so my understanding is that you are rotating the images, but not removing the orientation exif; hence exif-compliant software like Chrome rotates it again. Why can't we remove the tag ourselves?

https://github.com/saimn/sigal/blob/master/sigal/image.py#L73

 # Preserve EXIF data
    if settings['copy_exif_data'] and _has_exif_tags(img):
        if options is not None:
            options = deepcopy(options)
        else:
            options = {}
        options['exif'] = img.info['exif']

    # Rotate the img, and catch IOError when PIL fails to read EXIF
    try:
        img = Transpose().process(img)
        del options['exif']['Orientation']  # something like this

    except (IOError, IndexError):
        pass
@saimn

This comment has been minimized.

Owner

saimn commented Feb 12, 2014

Okay, so my understanding is that you are rotating the images, but not removing the orientation exif; hence exif-compliant software like Chrome rotates it again

Yes. The problem is that it is currently not possible to save the modified exif with Pillow. (There may be a possibility, hacking with the internal stuff of Pillow, but I did not managed to get it work yet)
A feature request has been filled : python-pillow/Pillow#520
Thus, the only solution I see for now is to add a new setting to disable the autorotation, and let the user choose between autorotation and exif copy (the 'copy_exif_data' setting).

@reagle

This comment has been minimized.

reagle commented Feb 12, 2014

Confirmed copy_exif_data = False does not have this problem in Chrome.

@reagle

This comment has been minimized.

reagle commented Feb 13, 2014

@saimn I'm not sure how long (if at all) the python-pillow/Pillow#520 will take to resolve, would you be opposed to a dependency on gexiv2. (gexiv2 is the update to pyexiv2, which is discussed in "How to use PIL to resize and apply rotation EXIF information to the file?".)

btw: jhead -norot does this nicely.

@saimn

This comment has been minimized.

Owner

saimn commented Feb 13, 2014

I was using pyexiv2 at the beginning (it was optional). But the installation of pyexiv2/gexiv2 is a problem, it is not available on pypi, so I don't want to add a dependency on this. And I don't know if it is easily installable on all platforms ?

saimn added a commit that referenced this issue Mar 10, 2014

New setting to disable autorotation of images, and warn about the
incompatibility between autorotation and EXIF copy (ref #72).
@reagle

This comment has been minimized.

reagle commented Mar 10, 2014

That's helpful, any news on an upstream fix from PIL?

@saimn saimn added the bug label Mar 31, 2014

@reagle

This comment has been minimized.

reagle commented Apr 1, 2014

Just looked about, don't see any evidence of the bug python-pillow/Pillow#520 receiving any attention nor of gexiv2 (as an alternative) appearing in pypi. However, there are a fair amount of exif tools in pypi such as exifyay. There's also img_rotate "Rotates PIL Image instances after EXIF-tagged image orientation" (however, it loses exif data as well). But maybe there's something there that could help.

@saimn

This comment has been minimized.

Owner

saimn commented Apr 1, 2014

img_rotate doesn't modify the EXIF data, it just rotate the images and doesn't the EXIF data. exifyay is more interesting but, even if it is available on pypi, you must compile it manually with cmake.

@reagle

This comment has been minimized.

reagle commented Jun 2, 2014

Any news on this front? Sadly, I don't see any change.

@saimn

This comment has been minimized.

Owner

saimn commented Jun 4, 2014

Hi Joseph,
Nope, no news. However I'm working on a plugin system for sigal, so one option could be to make a plugin for exifyay. This way it would not add a strong dependency to sigal, but it would be a good solution for people who need this feature.

@reagle

This comment has been minimized.

reagle commented Jan 2, 2016

I'm wondering if there's been any movement on this one?

@saimn

This comment has been minimized.

Owner

saimn commented Jan 4, 2016

Not really, except another project which could be useful to save modified EXIF data (and based on Pillow): https://pypi.python.org/pypi/piexif

@reagle

This comment has been minimized.

reagle commented May 31, 2017

I haven't seen any progress at python-pillow/Pillow#520, any fixes available here?

@saimn

This comment has been minimized.

Owner

saimn commented May 31, 2017

Nothing new here ...

@ghost

This comment has been minimized.

ghost commented Jun 8, 2017

Is there a workaround for this issue?

@saimn

This comment has been minimized.

Owner

saimn commented Jun 8, 2017

@jfleach - If you set only one of 'autorotate_images' and 'copy_exif_data', it should be ok: either rotate images and don't copy exif data, or copy exif and rely on browsers to do the rotation.

@anarcat

This comment has been minimized.

Contributor

anarcat commented Jan 3, 2018

In python-pillow/Pillow#2800, Pil is considering adding https://pypi.python.org/pypi/piexif as a dependency, so it seems there is movement there.

@anarcat

This comment has been minimized.

Contributor

anarcat commented Jan 3, 2018

And as for browser-based rotation, it's also mostly stalled, as I documented elsewhere (Upload/Up1#49 (comment)). Basically, earlier CSS4 drafts had image orientation extensions that allowed the browser to automatically rotate (or not) images based on CSS directives, but that was pulled from the standard. It was argued this was better served in the semantic layer (HTML) but nothing has come up there.

So far only firefox has support for the deprecated CSS4 directive and there's a patch pending for Chrome, but it's been 4 years so I wouldn't hold my breath on that one, especially considering the time it takes for browser changes to make it across the whole ecosystem.

We need to rotate images on our own (losslessly, if I might add) and modify the related exif data. It's annoying gymnastics, but it's not really something we can avoid right now, regardless of what the up1 people say. ;)

(Incidentally, it might be nice to link to this bug report in the source code, sample config or warning messages so that people can follow progress more easily. I missed this bug report while filing #279 earlier.)

@saimn

This comment has been minimized.

Owner

saimn commented Jan 3, 2018

Great news if Piexif could be used in Pillow !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment