5

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?

Alessandro Pezzato
  • 8,603
  • 5
  • 45
  • 63

1 Answers1

9

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

Dan Garland
  • 3,350
  • 1
  • 24
  • 24