MacOS Folder Action to watermark images using ImageMagick 6 for posting on Facebook

I wanted to prepare images to be posted on Facebook which means I needed to resize them to 1200x600 pixels and overlay a watermark.  I also want to keep a local copy of the image I post, so I decided to automate the image manipulations with a folder action and GraphicsMagick 1.3, which is available in MacPorts.  This is tested in Mojave and Catalina, but should work on most version of MacOS and OS X

NOTE: My solution modifies the image that is saved in the folder and makes no backup copies. It also creates a temporary file called "wm" in the watched folder, then deletes it.

Folder actions are performed on all new files that are put into a certain folder.  I created a new folder action in Automator with one action called "Run Shell Script".  In the top-right corner, I told Automator to pass the files as arguments to the script.  The script itself is shown below:


for f in "$@"
do
 dname=$(dirname "$f")
 /opt/local/bin/gm mogrify "$f" -resize 1200x630
 wmsize=$(/opt/local/bin/gm identify "$f" -format %wx%h)
 /opt/local/bin/gm convert "/Users/josh/Pictures/test-watermark.png" -resize $wmsize "$dname\wm"
 /opt/local/bin/gm composite -gravity center "$dname\wm" "$f" -dissolve 200 "$f"
 rm "$dname\wm"
done

So the workflow to make new image for a facebook post is simple:
1. Drag the desired image from Photos, Aperture, or anywhere else and drop it into the watched folder in Finder.

2. Wait a few seconds for the folder action to run.

3. Drag the watermarked file into the facebook post in Safari.

See below for a screenshot of Automator showing the folder action:
Automator Action

Comments

Popular posts from this blog

iChat IRC transport with OpenFire and Kraken

Save kerberos password in keychain for use with kinit on MacOS (was OS X) for use with network drives

Recording the iPhone screen and Mac screen at the same time in one video