How to use mogrify to crop an image

12.3k views Asked by At

I would like to use the Linux' mogrify tool to remove the lower 20 pixels of several images with all different dimensions.

Example: Image width is 800px, image heigth is 600px. I would like to crop the image that the new size is 800x580px where the 20px from the bottom are removed.

I am struggling with the Image Geometry object.

Is there a way to formulate an Image Geometry object without providing the absolute dimensions per image? An object which can be used on every image achieving the 20px crop mentioned above?

If not: Based on the example above, how does the Image Geometry object has to look like if I have to provide the current dimensions of an image?

Thanks a lot!

2

There are 2 answers

2
choroba On BEST ANSWER

Using -chop with -gravity should do the work:

mogrify image.jpg  -gravity south -chop x20

Nothe that gravity must precede the geometry settings to work. See ImageMagick for details

1
user1876422 On

Just found the answer based on chorobas approach:

mogrify -chop 0x20+0+0 -gravity South image.jpg

This site helped.