skip to Main Content

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:

ImageMagick Cropping Diagram

My original image looks like this:

Original Image

My cropped image looks like this:

Cropped Image

You can see there’s whitespace in my original image, what I want is to remove that.

2

Answers


  1. 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:

    $magick test2.png -crop 256x256+224+384 Cropped.png
    

    In this case if you only wanted to remove the white area you could use -trim:

    $magick test2.png -trim Cropped.png
    
    Login or Signup to reply.
  2. 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:

    magick input.png -trim +repage result.png
    

    enter image description here

    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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search