上传到网络时,iPhone相机图像会旋转 [英] iPhone camera images are rotated when uploaded to web
问题描述
我正在使用UIImagePickerController在iphone上以纵向模式拍摄照片并保存到网络上。照片在手机上以纵向显示,但在网络上旋转90度。
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.
如果我下载照片并在预览(mac)或Photoshop(mac)中查看或者pc)它再次成像。在Windows图片查看器(PC)中,它被旋转为横向。
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.
我需要在上传之前对图像数据应用旋转变换吗?那么我是否还需要删除在Photoshop和预览中旋转它的元数据?
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?
推荐答案
问题在于图像由于大多数浏览器都没有使用EXIF数据,因此将旋转添加到照片中。有两种解决方案:
The problem was that image rotation was added to the photo as EXIF data not used by most browsers. There are two solutions:
-
在服务器端应用轮换。我使用的是Ruby插件Paperclip(由Thoughtbot提供),只需要将自动定向转换选项包含在模型中的has_attached_file命令中:
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'}
has_attached_file :photo, :convert_options => { :all => '-auto-orient' }
在iPhone应用中旋转照片。这是在另一个stackoverflow问题中解决的;调用 scaleAndRotate方法将旋转元数据替换为图片转换,感谢@Squeegy。
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.
这篇关于上传到网络时,iPhone相机图像会旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!