我需要知道当前载波实例的宽度和高度
例如:
image_tag image.photo_url,:width => image.photo.width, :height => image.photo.height
但问题是image.photo.width和image.photo.height无效。
有什么想法吗?
答案 0 :(得分:5)
您必须安装ImageMagick,RMagick或MiniMagick。然后打开文件(图像),然后才能找到它的高度。
示例:https://github.com/jnicklas/carrierwave#conditional-versions(请参阅is_landscape?方法),复制到此处:
def is_landscape? picture
image = MiniMagick::Image.open(picture.path)
image[:width] > image[:height]
end
或其他相关问题: