Smart cropping of images and add border
You can use Imagemagick, available on Homebrew.

convert /path/to/in.png \
  -trim \
  +repage \
  -bordercolor White \
  -border 100x100 \
  /path/to/out.png



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
A +repage is performed on the virtual canvas to ‘flatten’ the crop.
The -border is added, in White.