我正在使用 Paperclip 的自定义样式来调整一些图像的大小。
自定义样式是这样定义的-
has_attached_file :image_preview,
:styles => lambda { |a|
{
:original => "#{a.instance.model.aspect_ratio_width.to_f/2.54*300}x#{a.instance.model.aspect_ratio_height.to_f/2.54*300}"}
}
当看到输出时,图像的宽度参数被调整了大小,但高度参数没有被调整!
同样在日志中,我看到在 ImageMagick 操作期间只考虑了宽度参数 --
Command :: file -b --mime '/tmp/46711c9258f556a83aa382084f5014d120160804-14501-h9qo6j.png'
Command :: identify -format '%wx%h,%[exif:orientation]' '/tmp/46711c9258f556a83aa382084f5014d120160804-14501-16cbj3b.png[0]' 2>/dev/null
Command :: identify -format %m '/tmp/46711c9258f556a83aa382084f5014d120160804-14501-16cbj3b.png[0]'
Command :: convert '/tmp/46711c9258f556a83aa382084f5014d120160804-14501-16cbj3b.png[0]' -auto-orient -resize "1110" '/tmp/caba5ed9a9c1d9623acb7738fd6b8dda20160804-14501-5sjqq1'
[paperclip] saving /cases/image_previews/000/000/045/original/Goku-Blue.png
我怎样才能做到这一点?
最佳答案
您可以像这样定义高度和宽度:
has_attached_file :image_preview, :styles { original: "1920x1080>", thumb: "300x300#"}
'#' 会将中心的图像剪切为给定的尺寸。
关于ruby-on-rails - 回形针 | ImageMagick - 无法使用自定义高度调整图像大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38769514/