josegonzalez/cakephp-upload — pull request #168 by joshuapaling (2013-10-01 11:48:16+00:00)
Title: honour exif data for jpg thumbnails (aka, prevent thumbnails showing up sideways)

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 data, meaning that many photos, when uploaded, have their thumbnails sideways / upside down, etc.

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.

exif 6
![exif6](https://f.cloud.github.com/assets/145042/1244796/e9fcab16-2a8e-11e3-9f57-c0c6733e90b4.JPG)

exif 8
![exif8](https://f.cloud.github.com/assets/145042/1244797/ea7f124a-2a8e-11e3-9ff6-bf55e7b47fc4.JPG)

exif 3
![exif3](https://f.cloud.github.com/assets/145042/1244798/eab9b9b8-2a8e-11e3-9cd1-9ea1cfe0d47b.JPG)

exif 1
![exif1](https://f.cloud.github.com/assets/145042/1244799/eb3c6994-2a8e-11e3-9077-c9b2c6f6d83d.JPG)

Signed-off-by: Joshua Paling