如何获取carrierwave当前实例的宽度和高度?Carrierwave图像尺寸
事情是这样的:
car_images.each do | image|
image_tag(image.photo_url, :width => image.photo_width, :height => image.photo_height)
end
不幸的是image.photo_width
和image.photo_height
不工作。 我需要指定图像的宽度和高度,它是我使用的jquery插件所必需的。如果使用Rmagick
class Image
before_save :update_image_attributes
private
def update_image_attributes
if image.present?
self.content_type = image.file.content_type
self.file_size = image.file.size
self.width, self.height = `identify -format "%wx%h" #{image.file.path}`.split(/x/)
# if you also need to store the original filename:
# self.original_filename = image.file.filename
end
end
end
这适用于新上传('image_changed?== true'),但测量现有附件的尺寸又如何?我似乎无法从控制台访问'get_geometry'方法。我得到了''私人方法'文件',称为''“。 –
2013-10-11 22:36:25