Batch processing images?

Have a really simple effect I would like to apply to a batch of images - to apply a 2px border to all. I have other apps that can do this (or at least I used to but they are quite old and may not work with Ventura), but ideally I'd like to this to be part of a larger process that I am running in KM.

What is the simplest method for achieving this? It really does not need to be anything too flashy, literally just add a border (to some PNG files).

Thanks :slight_smile:

Do you use Homebrew by any chance? Because ImageMagick can do this quite easily. If so, I can help. If not, no doubt others will chime in with some ideas.

I actually do, not a huge amount, but I have it mainly for installing apps on fresh Mac installs (I have a script that runs on Homebrew to install all the apps that are not from AppStore). So, I am somewhat familiar, but no expert :slight_smile:

If you are willing to install ImageMagick, then here’s a demo macro that uses it to add a 2-pixel border to each image file in the Finder’s selection. If you want to incorporate it into other workflows, the meat of the process is the shell script.

EDIT: Note, that if you have not run homebrew packages via Keyboard Maestro before, you may need to set up an environmental variable for it to execute properly. See this post for more info.

Download Macro(s): DEMO- Add 2 pixel border to each image in Finder’s selection.kmmacros (4.4 KB)

Macro-Image

Macro-Notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System Information
  • macOS 13.5.1
  • Keyboard Maestro v10.2
1 Like

Late reply, only just found a moment :slight_smile:

I installed ImageMagick via Brew, here: imagemagick — Homebrew Formulae

All installed OK :slight_smile:

I ran this Macro to set the path:

I then tried the macro that you supplied but got the following failure

Execute a Shell Script failed with script error: text-script: line 1: convert: command not found in macro “DEMO: Add 2 pixel border to each image in Finder’s selection” (while executing Execute Shell Script).

Have I missed something along the way? Hope you can help :slight_smile:

Sounds like KM is still unable to find the convert command, which is part of ImageMagick.

  1. Can you post the contents of your ENV_PATH variable please?
  2. Also, run the following command from Terminal and post those results as well: brew info imagemagick | pbcopy
    2a. You probably already know this, but the pbcopy will set the output to your clipboard so you can paste it right in to your reply here. Remove the | pbcopy if you want to see the output in Terminal)
Example Terminal output (click to expand/collapse)
==> imagemagick: stable 7.1.1-16 (bottled), HEAD
Tools and libraries to manipulate images in many formats
https://imagemagick.org/index.php
/opt/homebrew/Cellar/imagemagick/7.1.1-16 (809 files, 31.0MB) *
  Poured from bottle using the formulae.brew.sh API on 2023-09-18 at 08:45:21
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/i/imagemagick.rb
License: ImageMagick
==> Dependencies
Build: pkg-config
Required: freetype, ghostscript, jpeg-turbo, libheif, liblqr, libpng, libraw, libtiff, libtool, little-cms2, openexr, openjpeg, webp, xz, libomp
==> Options
--HEAD
	Install HEAD version
==> Analytics
install: 60,668 (30 days), 181,081 (90 days), 403,030 (365 days)
install-on-request: 55,832 (30 days), 166,148 (90 days), 370,046 (365 days)
build-error: 5 (30 days)

Hi @cdthomer , I appreciate all the help you offer on this forum. Outstanding, thank you.

I frequently have the need to process numerous .jpg images (4-10) that are large (sometimes like 3463 x 2309 and 7-10M)

Do you know if ImageMagic is able to process them in a batch to be something like:
750 x 500 or comparable, .jpg?

If not ImageMagic do you know of another stable way to achieve this?

Cheers

ImageMagick can definitely handle large images—I used it to reduce a bunch of massive NASA images down to 5K resolution. Yea, they were big :).

As for the specific command, because convert is so obtuse with some things, I used to search the web for each use case. Now, though, this is something the LLMs can do quite well. Ask your favorite engine something like this:

What's the imagemagick command (using "convert") to batch process images in a folder to reduct their size to a max of either 750 horizontal or 500 vertical, whichever is greater?"

It should provide a command that you can then easily test on a copy of a subset of your images to see if it works.

-rob.

1 Like

Happy to help where I can @troy!

In your Terminal, navigate to the directory where you have the images, and try the following command to resize them:

for file in *; do magick $file -resize 750x500 -extent 750x500 resized-$file; done

There are no doubt other ways to do this, but this one is rather simplistic. It should get you going, and if you have more questions feel free to ask.

NOTE: This is assuming those images are the only files in the directory... :wink:

2 Likes