Skip to content

ImageMagick

How to Batch Crop Images With Imagemagick

Crop a Single Image

  • We’ll start by looking at how to crop a single image using Imagemagick.
  • Open a command window in the folder containing the image(s) you want to crop.
  • Then open one of the images in Gimp or Photoshop to determine the x_size, y_size, x_offset, and y_offset as depicted ImageMagick Crop Layout
  • Finally use convert to test 1 image and confirm your crop settings
    1
    2
    3
    convert -crop x_sizexy_size+x_offset+y_offset inputfile outputfile
    
    convert -crop 1000x1000+38+278 Image.jpg CroppedImage.jpg
    

Batch Crop

Note

Now we could just loop over the images and crop, but we won’t thanks to Imagemagick’s batch processor mogrify. The command to crop a folder of images is very similar to cropping just 1.

  • First make a new folder called cropped to output cropped images to.
  • Next run the command as follows:

    1
    mogrify -crop 1000x1000+38+278 -path ./cropped *.jpg
    
  • That’s it, you’ve batch cropped your images.