I’m trying to crop an image using ImageMagick V7 on Linux CentOS 7 via the following command-line:
$convert -crop 256x256+224+384 test2.png Cropped.png
My input image is test2.png, my output image is Cropped.png. The input image is 480×640, and I want to crop it to 256×256.
The general form of the command-line is given by:
$convert -crop x_sizexy_size+x_offset+y_offset inputfile outputfile
ImageMagick cropping diagram:
My original image looks like this:
My cropped image looks like this:
You can see there’s whitespace in my original image, what I want is to remove that.
2
Answers
It works OK for me but your dimensions are a bit off – for the result I think you wanted.
Note V7 uses magick and not convert; convert uses a V6 legacy version.
You should read the input image ( in most cases ) before any operation. In V7 if you use the commands in the wrong order it can fail.
I used:
In this case if you only wanted to remove the white area you could use -trim:
It looks to me like you are trying to trim whitespace, in which case you’d be better using
-trim
as it will trim correctly regardless of colour (provided it is solid) and regardless of the amount of trimming required:I have added a red border purely for display purposes so you can see the extent of the cropped image even on Stack Overflow’s white background.