Just released: imageprep 6.2.0 with powerful new features

imageprep, my command line tool for batch-processing picture files, had a big update a week or so back — and now it has another one. With the second update imminent, I didn’t announce the first, 6.1.0, which I released to coincide with my post on writing command line utilities in Swift. That done, it’s time to shout about imageprep 6.2.0.

To get you up to speed, imageprep 6.1.0 centred on making some changes to bring it into line with some best practices I’d recently learned: sorting output for writing to the correct Unix/macOS file handles, Standard Output and Standard Error; trapping users’ keyboard-triggered interrupts; and presenting error messages in colour to raise their visibility.

That release also introduced the --createdirs flag to force imageprep to create any missing intermediate directories required to be able to write images at their specified destination. I also fixed a couple of bugs that had emerged in use.

imageprep 6.2.0 is focused on new features. First, I’ve added an --info argument to allow you to get a machine-readable list of the source files together with size and resolution information. I added it so that I can quickly get those values without firing up Photoshop or Pixelmator Pro on them individually.

Size relatively

I’ve also added the ability to crop, scale or pad images in one dimension only: imageprep will retain the source image’s height or width, as required.

Let’s say you have a 1000 x 2000-pixel image and you want to scale it to 2000 x 2000 pixels. Previously, you’d have to specify the exact dimensions, but now you simply use

imageprep -s $SOURCE_IMAGE -d $DESTINATION_IMAGE -a s 2000 x

Using x in place of the height value (or the width) tells imageprep to use the source image’s value, in this case 2000:

imageprep will crop, pad or scale images using the source images height or width
Scale the width while retaining the source image’s height

You can also perform operations that retain the aspect ratio — width divided by height — of the source image. This uses the symbol m in place of a height or width value.

Here’s an example: you want to scale a source image of unknown size down to a height (or width) of 128 pixels. To keep the final image ‘in pro’ with the source, ie. to ensure its width is scaled for you, you would enter:

imageprep -s $SOURCE_IMAGE -d $DESTINATION_IMAGE -a s m 128
imageprep can scale, crop or pad an image while retaining its aspect ratio
Use ‘m’ to get imageprep to calculate a dimension based on the source’s aspect ratio

Anchor crops

If you’ve ever used Photoshop or a similar tool, you may know that you can anchor crop operations to key points: the top right of the image, the bottom left and so on. GUI-based image editing applications usually present a 3 x 3 grid; you click on one of squares so defined and the tool crops the image from that point.

imageprep 6.2.0 uses the same idea; you just need to tell it which one of those grid-based anchor points you want to use. You use the --cropfrom flag to set the point. imageprep’s grid squares are numbered 0 through 8 from the top left, or you can use the codes TR, TC, TR, CL, CR, BL, BC or BR. TR is Top row, Right column; CL is Centre row, Left column; and BC is Bottom row, Centre column, and so on. With no anchor setting, ie. --cropfrom is not included in the command, imageprep centres the crop.

imageprep’s crop anchor grid values

As an example, if you crop a 2000 x 2000 image to 1000 x 1000 and use the the BL anchor point, the final image will be the bottom left corner of the original.

imageprep -s $SOURCE_IMAGE -d $DESTINATION_IMAGE -a c 1000 1000 --cropfrom BL

There’s one point to note. imageprep is a front-end for Apple’s sips tool, and sips has a long-running bug: when you crop from the top-left or bottom-left corners, the outcome is unpredictable. To deal with that, I have inset those two crops by a single horizontal pixel. It’s only noticeable on very small images, but it does mean that those two crops will be shifted fractionally. However, it ensures that sips crops correctly.

imageprep’s crop anchors work with the new aspect-ratio and dimension retention controls. So if you want to crop the left half of a 2000 x 2000-pixel image, for example, you would enter:

imageprep -s $SOURCE_IMAGE -d $DESTINATION_IMAGE -a c 1000 x --cropfrom CL

You can grab imageprep from my website or Brew tap. The source code is on GitHub.

PS. pdfmaker has been updated, to 2.3.0, too.