문제

I want to create a padded thumbnail, like described here

This command works:

convert src.png -thumbnail '200x200>' -gravity center -extent '200x200' dst.png

But this ruby code is not working: gravity is ignored

require 'mini_magick'
image = MiniMagick::Image.open('src.png')
image.thumbnail '200x200>'
image.gravity 'center'
image.extent '200x200'
image.write 'dst.png'

What's wrong with this code?

도움이 되었습니까?

해결책

You need to use combine_options with MiniMagick to roll all three of your commands together before you write it:

require 'mini_magick'
image = MiniMagick::Image.open('src.png')
image.combine_options do |c|
  c.thumbnail '200x200>'
  c.gravity 'center'
  c.extent '200x200'
end
image.write 'dst.png'

More info on the GitHub docs

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top