Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chop 4 sides of image with Imagemagick

I have the following image:

test PNG 1366x655 1366x655+0+0 8-bit sRGB 286KB 0.000u 0:00.000

and I need to chop it like this from the border of the image:

top: 140 px
bottom: 140 px
left: 180 px
right: 60 px

Is there a one-line command line to do this with convert?

like image 557
Gery Avatar asked Dec 03 '22 11:12

Gery


2 Answers

You can combine two -crops:

                      #left,top      right,bottom
convert test.png -crop +180+140 -crop -60-140 cropped.png
like image 85
that other guy Avatar answered Dec 29 '22 06:12

that other guy


The solution from that other guy is very clever. The standard way would be to use -chop. But that means 4 calls, since there is no symmetry in the sizes to be removed. So in ImageMagick using -chop, you could do

convert text.png -gravity north -chop 0x180 -gravity east -chop 60x0 -gravity south -chop 0x140 -gravity west -chop 140x0 cropped.png

See http://www.imagemagick.org/Usage/crop/#chop

See also -shave when there is symmetry either left/right or top/bottom or all around. http://www.imagemagick.org/Usage/crop/#shave

like image 27
fmw42 Avatar answered Dec 29 '22 06:12

fmw42