Smart cropping of images and add border

automatorcropgraphicsimage editing

I need to perform batch cropping to approximately 3000 images. Each image is for a different item.

What I need is a crop tool that can define the item from the background and add specific amount of pixels to the top, bottom, right and left of it.

For example, see the image below. Can I use Automator?

Best Answer

You can use Imagemagick, available on Homebrew.

convert /path/to/in.png \
  -trim \
  +repage \
  -bordercolor White \
  -border 100x100 \
  /path/to/out.png
  1. The image is trimmed using -trim operation which removes the border from the image.

    This option removes any edges that are exactly the same color as the corner pixels. Use -fuzz to make -trim remove edges that are nearly the same color as the corner pixels.

    http://www.imagemagick.org/script/command-line-options.php

  2. A +repage is performed on the virtual canvas to ‘flatten’ the crop.

  3. The -border is added, in White.