2016-08-04 62 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

寬度的高度是動態給定的。 –