img标签显示错误的方向 [英] img tag displays wrong orientation
问题描述
我在此链接上有一张图片: http ://d38daqc8ucuvuv.cloudfront.net/avatars/216/2014-02-19%2017.13.48.jpg
I have an image at this link: http://d38daqc8ucuvuv.cloudfront.net/avatars/216/2014-02-19%2017.13.48.jpg
如您所见,这是具有正确取向的正常图像。但是,当我将此链接设置为我的图像标记的src属性时,图像会上下颠倒。 http://jsfiddle.net/7j5xJ/
As you can see, this is a normal image with correct orientation. However, when I set this link to src attribute of my image tag, the image becomes upside down. http://jsfiddle.net/7j5xJ/
<body>
<img src="http://d38daqc8ucuvuv.cloudfront.net/avatars/216/2014-02-19%2017.13.48.jpg" width="200"/>
</body>
你有什么想法吗?
感谢
推荐答案
我忘了在这里添加我自己的答案。我使用Ruby on Rails,所以它可能不适用于您的PHP或其他框架中的项目。在我的情况下,我使用载波波宝上传图像。我的解决方案是在保存文件之前,将以下代码添加到uploader类中以修复EXIF问题。
I forgot to add my own answer here. I was using Ruby on Rails so it might not be applicable to your projects in PHP or other frameworks. In my case, I was using Carrierwave gem for uploading the images. My solution was to add the following code to the uploader class to fix the EXIF problem before saving the file.
process :fix_exif_rotation
def fix_exif_rotation
manipulate! do |img|
img.auto_orient!
img = yield(img) if block_given?
img
end
end
这篇关于img标签显示错误的方向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!