5

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... :)

9

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> <height>x<width>+<pos x>+<pos y> <output filepath>
    

Cropping Images with ImageMagick

If I want to crop all the images into:

  • Height: 300px
  • Width: 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

  • I tried this but it only resized one image. It took me a while to work out that the path must include a file name. I wanted the files in ./done, so had to use result path like ./done/cropped.png to get files cropped-0.png, cropped-1.png and so on. How can I keep the original file name? – RobG Aug 24 '17 at 2:53
  • Oh, use mogrify instead of convert. – RobG Aug 24 '17 at 3:04
0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .