Search code examples
graphicsmagick

Resize and crop image using graphicsmagick


I'm using gm convert -geometry "XxY^>", this does resize the image but it doesn't crop it. Suppose I've got a 100 x 100 image and want to have a 20 x 30 version, the current command will return a 30 x 30 version. How do I crop this to 20 x 30? Just -crop 20x30 returns the left part, while I'd like to have the center part.


Solution

  • I think you want to set the gravity before cropping:

    gm convert image.png -gravity center -crop 20x30+0+0 result.png