How to crop an image using imagemagick from the command line?

9

3

I have a 640 x 640 image... I am trying to crop the image using imagemagick (https://www.imagemagick.org/script/command-line-options.php#shave)

from the command line. I need to remove about 20 pixels from the bottom part of the image all the way from left to right. (a long strip along the bottom).

What would be the command to enter in the command line? I am using the windows version of this software. Thank you!

user2041357

Posted 2016-12-28T04:22:51.320

Reputation:

Answers

10

Use ImageMagick's -chop operator as follows to remove 20 rows of pixels from the bottom:

convert image.png -gravity South -chop 0x20 result.png

Change to -gravity North to chop top 20 rows.


Change to:

convert image.png -gravity East -chop 20x0 result.png

to crop from right side, note that the 20 pixels are now before the x separator.

Mark Setchell

Posted 2016-12-28T04:22:51.320

Reputation: 221

Remove the zero (as in 1x20) to actually remove anything – yPhil – 2018-09-09T10:24:07.110

8

Assuming that you always know the size of your image you can do it like this:

convert original.jpg -crop 640x620+0+0 cropped.jpg

With the -crop operator you specify the size of the cut out image and the offset from the upper left corner of the old image. In order to get rid of the 20px along the bottom, you have to choose a size of 640x620 and an offset of 0+0

Alex Maiburg

Posted 2016-12-28T04:22:51.320

Reputation: 181