#!/bin/bash # watermark -- add specified text as a watermark on the input image # saving the output as image+wm setglobal wmfile = ""/tmp/watermark.$Pid.png"" setglobal fontsize = '"44'" # should be a starting arg trap "$[which rm] -f $wmfile" 0 1 15 # no temp file left behind if test $Argc -ne 2 { echo "Usage: $[basename $0] imagefile "watermark text"" > !2 ; exit 1 } if test ! -r $1 { echo "$[basename $0]: Can't read input image $1" > !2 ; exit 1 } # to start, get the dimensions of the image setglobal dimensions = $[identify -format "%G" $1] # now let's create the temporary watermark overlay convert -size $dimensions xc:none -pointsize $fontsize -gravity south \ -draw "fill black text 1,1 '$2' text 0,0 '$2' fill white text 2,2 '$2'" \ $wmfile # echo "created watermark file with dimensions $dimensions" # now let's composite the overlay and the original file setglobal suffix = $[echo $1 | rev | cut -d. -f1 | rev] setglobal prefix = $[echo $1 | rev | cut -d. -f2- | rev] setglobal newfilename = ""$prefix+wm.$suffix"" composite -dissolve 75% -gravity south $wmfile $1 $newfilename echo "Created new watermarked image file $newfilename" exit 0