2016-08-04 65 views
4

我正在使用Paperclip的自定义样式来调整一些图像的大小。回形针| ImageMagick - 无法使用自定义高度调整图像大小

自定义风格的定义是这样 -

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 

我怎样才能做到这一点?

回答

0

可以定义的高度和宽度等的是:

has_attached_file :image_preview, :styles { original: "1920x1080>", thumb: "300x300#" }

的“#”将削减图像中的中心到给定尺寸。

https://github.com/thoughtbot/paperclip#quick-start

+0

宽度的高度是动态给定的。 –