Ruby on Rails-Carrierwave获取图像尺寸的宽度和高度 [英] Ruby on Rails - Carrierwave get the image dimension width and height
本文介绍了Ruby on Rails-Carrierwave获取图像尺寸的宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要知道当前载波的宽度和高度
I need to know the width and height of the current instance of carrierwave
例如:
image_tag image.photo_url,:width => image.photo.width, :height => image.photo.height
但是问题是image.photo.width和image.photo.height
But the problem is that image.photo.width and image.photo.height are not working.
任何想法吗?
推荐答案
安装ImageMagick,RMagick或MiniMagick。然后打开文件(图像),然后找出其高度。
You have to install ImageMagick, RMagick or MiniMagick. Then you open the file (image) before you can find out its height.
示例: https://github.com/jnicklas/carrierwave#conditional-versions (请参见is_landscape?方法),复制到此处:
Example: https://github.com/jnicklas/carrierwave#conditional-versions (see the is_landscape? method), copied here:
def is_landscape? picture
image = MiniMagick::Image.open(picture.path)
image[:width] > image[:height]
end
或其他相关问题:
这篇关于Ruby on Rails-Carrierwave获取图像尺寸的宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文