When you upload an image that exceeds the imagefield allowed size (width x height), autorotate won't work if you are using GD. That's because GD downsizes the image and clears EXIF before any image style effects are applied. I couldn't find a way to save EXIF during GD transformations, so there are two possible workarounds: not to set the size restrictions for an imagefield (to prevent GD transformations) or to use ImageMagick (to preserve EXIF).

When you add the autorotate effect to an image style there's a message "...it is better to start each image style with this effect". It would be great to add the notice: "If you're using GD, do not resize uploaded images before applying an image style".

Also rotating large images requires a lot of memory. If you've just removed the imagefield restrictions and now the images aren't shown at all, then check the logs and try to increase PHP memory_limit. For example, rotating 3 MB photo often requires more than 128 MB memory.

Comments

fietserwin’s picture

I guess that instead of us (i.e. this contrib module) reporting this to users who apparently have come so far, I would suggest to change this to a core request to autorotate uploaded images that are going to be resized or even better to autorotate all uploaded images, regardless used toolkit.

As an intermediate (D8) solution, we could go for your message on the upload field help text, not the autorotate help text.

There are a few situations we should tackle though:
- memory consumption when using GD might indeed be a problem. So I guess we should do that in a smart way: read exif data, resize, rotate (based on read exif data)
- autorotate will also delete exif data when using GD, so it should probably be an option on the image field (like the max dimensions are currently).

What do you think?

dman’s picture

Interesting points.
I guess that most folk don't think of the core size restrictions as a 'resize' action in itself (even though it is).
Yeah, GD drops all metadata all the time. And yeah, it's memory-hungry (but anyone who thinks a 3MB image is a good idea on a website should probably be choosing ImageMagick anyway.)
Nah, we can't do anything about that by the time it hits imagecache_actions. Pushing metadata in somewhere upstream like that sounds cute - if there is a hook for that. Maybe not in core, but I can sorta imagine it getting into media.module suite, maybe. At least that believes in metadata.

ankheg’s picture

fietserwin, "a core request to autorotate uploaded images" seems to be a good idea. Actually it is quite annoying, when you see a properly oriented image in your OS image viewer, and then, after uploading it to the web, you suddenly see it laying. Everybody'll like autorotate option for imagefields.

Also it's more meaningful to rotate image once on upload, then rotating it for every image style.

I suppose I'll write a core request and will try to make a patch.

fietserwin’s picture

Status: Active » Closed (won't fix)

Did you file an issue with core? If so, it would be nice to post a link to it here, so other people who arrive on this page by search, can be forwarded to the correct issue.

nerdoc’s picture

Any progress on this? Is there a core bug?
I can't believe that such a "common" and wide-spread problem (image uploading and rotating!) won't be addressed properly in core?

dman’s picture

It's a missing feature maybe.
But nobody yet seems to have been either frustrated enough or sponsored enough to have a go at it.
I *can* believe that.

The way forward is open to propose a solution to this feature request. I would endorse a solution as sensible.

Ideally, I'd prefer if GD toolkit allowed us to retain or manipulate metadata, but until then, I think it'd be asking all web servers to install an extra binary (exiftool) on their system. Php exif is weak.

fkelly12054@gmail.com’s picture

For what it's worth ... I have encountered a version of this problem on a test Drupal 8.0.1. site I am working on. Basically, it appeared Drupal was ignoring exif rotation information. After googling around about exif and rotation for a few hours, I concluded that the problem is not limited to Drupal, a lot of web sites ignore or get wrong the exif info about rotation / orientation. With people flipping their cell phone cameras vertical and horizontal all the time these days this problem will be more and more common.

I traced the problem back a little and found it existed on my Drupal 7 site also. So, it obviously was not created by Drupal 8 (this thread is perfect evidence too).

I was able to create a crude workaround by modifying the image styles to put rotate 90 degrees at the top of the effects for both the thumbnail styles and the larger styles. I think that will handle most situations where someone just flips the smartphone upright to take the picture. Down the road I suspect there will need to be a more thorough solution for working with images in Galleries on Drupal.

fkelly12054@gmail.com’s picture

So much for my crude workaround. Now images that are in so-called landscape mode to start with get flipped vertically. Drupal needs to read the exif info. correctly.