Question

I'm trying to crop large batches of images automatically. I'm currently using Automator's Crop Images action, but it is lacking in options. I can specify a width and height, and then it performs a centered crop. I want to be able to specify X and Y as well as width and height (to use Xcode terms), so I can perform a consistent crop for any custom rectangle. Are there better, more featureful cropping actions available? Preferably for free... :)

Was it helpful?

Solution

Here is a way to achieve what you want with ImageMagick. Hopefully you’re comfortable using Terminal (and also use Homebrew to manage all your packages).

Either way, you must install ImageMagick so you can run convert command line in Terminal.

  1. Open the folder you want to batch processing all the images. If your folder name called images is located on Desktop, you’ll need to enter cd ~/Desktop/images/ in Terminal.

  2. ImageMagick have a built-in option to crop images according to sizes and coordinates. The command is:

     convert <input documents> <width>x<height>+<pos x>+<pos y> <output filepath>
    

Cropping Images with ImageMagick

If I want to crop all the images into:

  • Width: 300px
  • Height: 500px
  • Position X: 100px from top left
  • Position Y: 70px from top left

I can enter the command below:

convert *.jpg -crop 300x500+100+70 result/screenshot.jpg

Make sure the target filepath exists. In this case, you should create a folder called result in Desktop. Or you can use absolute path like ~/Desktop/result or whatever folder you want to point. Just drag the folder into Terminal like this:

Dragging Folder into Terminal

OTHER TIPS

ImageMagick convert worked for me, but only after I wrapped it in a for-loop:

for filename in *.jpg; do\
  convert $filename -crop {height}x{width}+{position-x}+{position-y} "result/$filename"
  echo "$filename done"
done
Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top