Skip to content

Instantly share code, notes, and snippets.

@rbrady
Created June 24, 2017 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rbrady/01b535ec908c0c75ae8941de706e828b to your computer and use it in GitHub Desktop.
Save rbrady/01b535ec908c0c75ae8941de706e828b to your computer and use it in GitHub Desktop.
Resize and Watermark images with ImageMagick
#!/bin/bash
# change dir to the first arg to the script
cd $1
if [[ "$2" != "" ]]; then
FONT_TYPE="$2"
else
FONT_TYPE="Helvetica"
fi
if [[ "$3" != "" ]]; then
ALT_FONT_TYPE="$3"
else
ALT_FONT_TYPE="Helvetica"
fi
# create resized dir
mkdir resized
# lookup files with extension
for fname in *.*; do
final_file="./resized/$(echo $fname | cut -d'.' -f1).png"
# resize, sharpen and convert
echo "processing $fname"
mogrify -quality 96% -format png -write "$final_file" -resize 12% "$fname"
# watermark
echo "watermarking $final_file, using $FONT_TYPE"
convert "$final_file" -font $FONT_TYPE -pointsize 36\
-draw "gravity center \
fill white text 0,-20 'Monica Brady Photography' " \
"$final_file"
convert "$final_file" -font $ALT_FONT_TYPE -pointsize 32 \
-draw "gravity center \
fill white text 5,30 'monicabrady.net' " \
"$final_file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment