iPhone 相机图像上传到网络时会旋转
我正在使用 UIImagePickerController 在 iPhone 上以肖像模式拍摄照片并将其保存到网络上。 照片在手机上以纵向显示,但在网络上会旋转 90 度。
如果我下载照片并在预览 (Mac) 或 Photoshop(Mac 或 PC)中查看它,它会再次处于纵向状态。 在 Windows 图片查看器 (pc) 中,它会旋转为横向。
上传之前是否需要对图像数据应用旋转变换? 那么我是否还需要删除在 Photoshop 和预览中旋转它的元数据?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果图像在 MS Windows 中以正确的方向保存,这里有一种手动覆盖 EXIF 旋转元数据的简单方法。 在 Windows 资源管理器中,右键单击图像文件并选择“顺时针旋转”。 执行此操作 4 次以将图像旋转一圈,然后图像将具有适合所有系统的正确方向。 然后您可以将图像上传到您的网络服务器。
Here is an easy way to manually override the EXIF rotation metadata, if the image is saved in the correct orientation in MS Windows. In Windows Explorer, right-click on the image file and select "Rotate clockwise". Do this 4 times to rotate the image all the way around, and then the image will have the correct orientation for all systems. Then you can upload the image to your web server.
问题是图像旋转被添加到照片中作为大多数浏览器不使用的 EXIF 数据。 有两种解决方案:
在服务器端应用轮换。 我使用的是 Ruby 插件 Paperclip(由 Thoughtbot 提供),只需将自动定向转换选项包含到模型中的 has_attached_file 命令中即可:
has_attached_file:照片,:convert_options => {:全部=> '-auto-orient' }
在 iPhone 应用程序中旋转照片。 这在另一个 stackoverflow 问题中得到了解决; 调用 scaleAndRotate 方法 将旋转元数据替换为图像变换,感谢 @Squeegy。
The problem was that image rotation was added to the photo as EXIF data not used by most browsers. There are two solutions:
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' }
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.
以下是 CarrierWave/MiniMagick 的解决方案: http://carrierwave.rubyforge.org /rdoc/classes/CarrierWave/MiniMagick.html
Here is a solution for CarrierWave/MiniMagick: http://carrierwave.rubyforge.org/rdoc/classes/CarrierWave/MiniMagick.html
一旦您在将图像上传到服务器之前拍摄照片,只需将拍摄的图像传递到一个方法中,它肯定适合您
Once you take the photo before uploading the image to the server just pass your taken image into a method and its surely works for you