Posted by CANbike on Wed, 28 Aug 2013

Images: Batch Auto Crop White Space

Batch-Auto Crop-Minimize White Space-01-thumb.jpgBatch-Auto Crop-Minimize White Space-02-thumb.pngBatch-Auto Crop-Minimize White Space-03-thumb.jpg

Recently, objects shot with white backgrounds were photographed. But before using those photographs, they had to be processed. The objects had to be cropped out to minimize the solid white background.

Fortunately, there was a simple way to automate this batch process task with ImageMagick!

Auto Crop Images

The following is a batch command to auto crop images to minimize the solid background. The solid background can be any color and is not limited to white space.

mogrify -fuzz 15% -trim +repage *.jpg


Removes any edges that are the same color as the corner pixels.

Alters the -trim algorithm to match a range of colors in a similar RGB space. It is especially useful for compressed images and photographs where the background can vary slightly in color.*

Resets the virtual canvas of the image. -trim maintains the original canvas size information after cropping. +repage removes the information, resulting in a new virtual canvas matching the cropped dimensions of the image.

Wildcard pattern to process all files ending with “.jpg”.

*From my own experience, an aggressive 15-25% is good for photographs with solid backgrounds.


For complete documentation on cropping, visit

Related Item(s):