Paper clips | ImageMagick - unable to resize image with custom height

I use custom Paperclip styles to resize some images.

Custom style is defined as follows:

  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}"}
                  }

When the image is visible, the image resized the width parameter, but there was never a height parameter!

The logs also show that during the ImageMagick operation, only the width parameter was taken into account -

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

How can i do this?

+4
source share
1 answer

You can define the height and width:

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

"#" will cut the image in the center to the specified size.

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

0

Source: https://habr.com/ru/post/1650182/


All Articles