【发布时间】:2010-05-04 19:52:55
【问题描述】:
尝试在初始保存时仍在模型中时获取上传图像的宽度和高度。
有什么办法吗?
这是我从我的模型中测试的代码的 sn-p。当然它在“instance.photo_width”上失败了。
has_attached_file :photo,
:styles => {
:original => "634x471>",
:thumb => Proc.new { |instance|
ratio = instance.photo_width/instance.photo_height
min_width = 142
min_height = 119
if ratio > 1
final_height = min_height
final_width = final_height * ratio
else
final_width = min_width
final_height = final_width * ratio
end
"#{final_width}x#{final_height}"
}
},
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => ":attachment/:id/:style.:extension",
:bucket => 'foo_bucket'
所以我基本上是在尝试这样做,以根据初始图像尺寸获得自定义缩略图的宽度和高度。
有什么想法吗?
【问题讨论】: