honour exif data for jpg thumbnails (aka, prevent thumbnails showing up sideways) #168
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
OK... this is a pretty important issue - no idea how this hasn't come up before, but about a hundred users have just signed up to a site I'm doing, and a decent percentage have sideways profile thumbnails!
The reason is this plugin doesn't honour an images exif orientation data, meaning that many photos, when uploaded, have their thumbnails sideways / upside down, etc.
This pull request fixes that - and doesn't change anything for images which are not JPG's with Exif Orientation data.
You probably know most of this, but I'll assume no knowledge just in case...
Some JPG's store "Exif" data, containing info like the images geolocation, and, importantly, orientation. If a camera is held eg. upside down to take a photo, the raw image is stored upside down, but the Exif Orientation data indicates that it should be rotated 180 degrees to be displayed.
Since most browsers interpret exif data, original images uploaded with this plugin will display fine - but the thumbnails made from them will not, because the exif data isn't transformed to the thumbnail. This pull request checks for exif orientation data in an image, and if it's present, adjusts the image appropriately (flips or rotates it). So, the thumbnail will be adjusted to display correctly, without the exif data.
I've followed this to get image orientation from exif data: http://www.impulseadventure.com/photo/exif-orientation.html
I've got no idea how you'd write tests for this, since the uploads themselves are mocked... if you've got ideas for how to auto-test, I'm happy to write the tests.
I have tested thoroughly, manually. I've tested images with exif orientations of 1, 3, 6 and 8, and I've tested for both php and imagick thumbnail methods. The other 4 orientation cases - 2, 4, 5, and 7 - are rare; they are when the image is flipped, and I don't have a camera that produces them. But I've coded carefully, and in any case, those cases can't be more broken than they already are!
If you want to test manually, here are some images with different exif orientation values (not sure if github will preserve the exif data, but you can make your own by just taking 4 photos with your iphone, rotating 90 degrees more for each one.
(UPDATE - as you can see, Github doesn't honour the exif data when displaying the images inline, but open each in a new tab and it will display correctly)
exif 6
![exif6](https://camo.githubusercontent.com/85ba06763468832b33231ff6c8f686d0cbcfac983a9134f0722402083d7aa55a/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f3134353034322f313234343739362f65396663616231362d326138652d313165332d396635372d6330633637333365393062342e4a5047)
exif 8
![exif8](https://camo.githubusercontent.com/fffe69dd51824b35db3e9b975e152340d41e6eab440d59d9d721d7aff99a1864/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f3134353034322f313234343739372f65613766313234612d326138652d313165332d396666362d6266353565376234376663342e4a5047)
exif 3
![exif3](https://camo.githubusercontent.com/7d69acaad8cb5463add6b1a67c56f986d8550b212e2348e93874fcf1b673335d/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f3134353034322f313234343739382f65616239623962382d326138652d313165332d396364312d3965613163666530643437622e4a5047)
exif 1
![exif1](https://camo.githubusercontent.com/3f34fac01bb079db630f6d5990aca0836413ffcb0c8cfc8894ff83caad58a1fe/68747470733a2f2f662e636c6f75642e6769746875622e636f6d2f6173736574732f3134353034322f313234343739392f65623363363939342d326138652d313165332d393037372d6339623263366636643833642e4a5047)
Signed-off-by: Joshua Paling joshua.paling@gmail.com