This will only work on the Mac, and has only been tested with an app called Context Menu1, and requires Imagemagick and other tools installed via Homebrew, and other things I’m probably omitting, but this is a little script I wrote that will work in the Mac context menu to automatically resize any image type you specify and output it with “-smaller” appended.
Here’s how it looks in my right-click menu:
And here’s my glorious code:
#!/bin/bash
for f in "$@"
do
# Get the width and height of the original image
dimensions=$(sips -g pixelWidth -g pixelHeight "$f")
width=$(echo "$dimensions" | awk '/pixelWidth:/ { print $2 }')
height=$(echo "$dimensions" | awk '/pixelHeight:/ { print $2 }')
if [ "$width" -gt 1200 ] || [ "$height" -gt 1200 ]; then
# Get file name without extension and the extension
filename="${f%.*}"
extension="${f##*.}"
# Output file name
output="${filename}-smaller.${extension}"
# Copy original to new file first
cp "$f" "$output"
# Resize and set DPI using mogrify
/opt/homebrew/bin/mogrify -resize 1200x1200\> -density 96 -units PixelsPerInch "$output"
else
# Show dialog with custom icon if image is too small
osascript <<EOF
set iconFile to POSIX file "/Users/quoderat/icons/10112-crying-cat-face-icon.png" as alias
display dialog "Image is too small, home slice." buttons {"OK"} default button "OK" with icon iconFile
EOF
fi
done
It should be noted that if you attempt to resize an image that is smaller than 1200 pixels width/height the script will pop up a dialog box that says, “Image is too small, home slice.”
Tune that puppy how you want. It has comments and it’s pretty obvious what it’s doing and how.