views:

522

answers:

1

I'm using UIImagePickerController to take a photo in portrait mode on the iphone and save to the web. The photo appears in portrait on the phone, but rotates 90 degrees on the web.

If I download the photo and look at it in Preview (mac) or Photoshop (mac or pc) it is in portrait again. In Windows Picture Viewer (pc) it's rotated to landscape.

Do I need to apply a rotation transform to the image data before uploading? Will I then also need to remove the meta-data that's rotating it in Photoshop and in Preview?

+1  A: 

The problem was that image rotation was added to the photo as EXIF data not used by most browsers. There are two solutions:

  1. Apply the rotation on the server side. I was using the Ruby plugin Paperclip (by Thoughtbot) and just had to include the auto-orient convert option to the has_attached_file command in the model:

    has_attached_file :photo, :convert_options => { :all => '-auto-orient' }

  2. Rotate the photo within the iPhone app. This was solved in another stackoverflow question; calling the scaleAndRotate method replaces the rotation meta-data with an image transform, thanks to @Squeegy.

Arrel