我正在尝试根据上传的图片尺寸制作不同版本的图片,我不明白为什么我的代码没有保存宽度和高度值。我正在使用Carrierwave。这是我的代码:
class HeadUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
#Create different versions of your uploaded files:
version :thumb do
process :image_dimensions
width = @geometry.width
height = @geometry.height
if width < height
process :resize_to_limit => [30, 60]
else
process :resize_to_limit => [60, 30]
end
end
def image_dimensions
manipulate! do |img|
@geometry = { width: img.columns, height: img.rows }
end
end
end
对于第width = @geometry.width
行,我收到以下错误:undefined method 'width' for nil:NilClass
您认为什么可能是个问题?