img 标签显示错误的方向 [英] img tag displays wrong orientation

查看:27
本文介绍了img 标签显示错误的方向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个链接有一张图片: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/

<img src="http://d38daqc8ucuvuv.cloudfront.net/avatars/216/2014-02-19%2017.13.48.jpg" width="200"/>

你知道发生了什么吗?

推荐答案

我忘了在这里添加我自己的答案.我使用的是 Ruby on Rails,所以它可能不适用于 PHP 或其他框架中的项目.就我而言,我使用 Carrierwave gem 上传图像.我的解决方法是在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆