0

我正在实现回形针,我要上传的图像有不同的尺寸。我希望每个图像的缩略图高 100 像素并保持上传图像的纵横比。有没有办法在如下语句中定义该标准?

 has_attached_file :image, :styles => { :standard => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"

会像以下工作:

:styles => lambda { |a|
                    height_quotient = a.instance.height / 100    
                    { :thumb => "#{(a.instance.width / height_quotient) }x100#" }
                  }

我将尝试这个,但如果您发现问题,请提供反馈。谢谢。

4

1 回答 1

0

默认的调整大小选项似乎保持纵横比。例如:

has_attached_file :image, :styles => { :standard => "300x300>", :thumb => "100x100>" }, :default_url => "/images/:style/missing.png"

@object.image.url(:standard)调用时以适当的纵横比调整图像大小。

于 2013-06-01T15:01:29.320 回答