Skip to content

Instantly share code, notes, and snippets.

@mbrevoort
Created January 4, 2016 03:31
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 mbrevoort/a41dc5040362c720c803 to your computer and use it in GitHub Desktop.
Save mbrevoort/a41dc5040362c720c803 to your computer and use it in GitHub Desktop.
#!/bin/bash
# takes a directory as the first argument and loops through all of the jpg
# images watermarking them into a watermark folder within that directory.
DIRECTORY=$1
WATERMARK=$2
mkdir -p $1/watermark
for filename in $DIRECTORY/*
do
if [[ ! -d $filename ]]; then
BASE=$(basename "$filename" .jpg)
EXT="${filename##*.}"
if [ "$EXT" = "jpg" ]; then
OUTPUT="$1/watermark/$BASE.$EXT"
echo "$filename --> $OUTPUT"
ww=`convert $filename -format "%[fx:.20*w]" info:`
hh=`convert $filename -format "%[fx:.20*h]" info:`
isPortait=`echo $hh'>'$ww | bc -l`
if [ $isPortait -eq 1 ]; then
ww=`convert $filename -format "%[fx:.30*w]" info:`
hh=`convert $filename -format "%[fx:.30*h]" info:`
fi
composite -gravity SouthWest -geometry +50+50 \( $WATERMARK -resize ${ww}x${hh} \) $filename $OUTPUT
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment