Skip to content
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 · 28 comments · May be fixed by #422
Open

Autorotate gallery images #72

reagle opened this issue Feb 4, 2014 · 28 comments · May be fixed by #422
Labels

Comments

@reagle
Copy link

@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
Copy link
Owner

@saimn 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
Copy link
Author

@reagle reagle commented Feb 12, 2014

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

@reagle
Copy link
Author

@reagle 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
Copy link
Owner

@saimn 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
Copy link
Author

@reagle reagle commented Feb 12, 2014

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

@reagle
Copy link
Author

@reagle 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
Copy link
Owner

@saimn 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
incompatibility between autorotation and EXIF copy (ref #72).
@reagle
Copy link
Author

@reagle 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
Copy link
Author

@reagle 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
Copy link
Owner

@saimn 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
Copy link
Author

@reagle reagle commented Jun 2, 2014

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

@saimn
Copy link
Owner

@saimn 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
Copy link
Author

@reagle reagle commented Jan 2, 2016

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

@saimn
Copy link
Owner

@saimn 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
Copy link
Author

@reagle reagle commented May 31, 2017

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

@saimn
Copy link
Owner

@saimn saimn commented May 31, 2017

Nothing new here ...

@ghost
Copy link

@ghost ghost commented Jun 8, 2017

Is there a workaround for this issue?

@saimn
Copy link
Owner

@saimn 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
Copy link
Contributor

@anarcat 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
Copy link
Contributor

@anarcat 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
Copy link
Owner

@saimn saimn commented Jan 3, 2018

Great news if Piexif could be used in Pillow !

@saimn
Copy link
Owner

@saimn saimn commented Aug 26, 2019

Pillow 6.0 added the possibility to modify the EXIF metadata and added ImageOps.exif_transpose :)
https://pillow.readthedocs.io/en/stable/releasenotes/6.0.0.html#added-imageops-exif-transpose

@reagle
Copy link
Author

@reagle reagle commented Dec 10, 2020

Any news?

@saimn
Copy link
Owner

@saimn saimn commented Dec 11, 2020

Not really, the feature is in Pillow but time is lacking to update the code to use it.

@hjbaader
Copy link

@hjbaader hjbaader commented Jan 5, 2021

I just looked at the code in this area. For me the images themselves get rotated correctly, but the thumbnails not. It looks like Transpose is missing from the thumbnail generation, is that correct?

@virtadpt
Copy link

@virtadpt virtadpt commented Jan 5, 2021

That seems to be the case, I'm seeing the same thing over here.

@hjbaader
Copy link

@hjbaader hjbaader commented Jan 6, 2021

Indeed. I added a parameter autorotate to generate_thumbnail and a passage to call Transpose in the same way as in generate_image and it seems to work.

@saimn
Copy link
Owner

@saimn saimn commented Jan 15, 2021

This is another issue, but I have seen that recently too and committed a fix (a77b2e3).
That should happen only with use_orig = True because otherwise the thumbnails are created from the resized images which are rotated.

@saimn saimn linked a pull request that will close this issue Feb 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants