Adding a Watermark to an Image

This is a common need – how do I add a watermark to an image I have created?

As it became obvious that other sites were not indicating where content was being leeched from, it was clear a another look at doing this was required.

This shell script is designed to loop through a number of RASP images and overlay a watermark to make aware where it has come from.

#!/bin/sh
# Script to add watermark on images
CONVERT_BIN=/usr/bin/convert
COMPOSITE_BIN=/usr/bin/composite

if [ "$1" != "" ]; then

        HOMEDIR=/home/rasp
        TARGETREGION=$1
        LOCATION=$HOMEDIR/$TARGETREGION/HTML/$TARGETREGION/FCST
        TMP_LOCATION=/tmp
        TARGET_LOCATION=$HOMEDIR/$TARGETREGION/HTML/$TARGETREGION/FCST
        SITENAME=
        WM_LOGO=$HOMEDIR/water-mark-logo.png
        WM_STAMP=/tmp/stamp_mask.png
        echo $HOMEDIR
        echo $TARGETREGION
        echo $LOCATION
        echo $TARGET_LOCATION
        echo $SITENAME
else
        echo "Provide a region to sync"
fi

        rm -f $WM_STAMP

  $CONVERT_BIN -size 553x213 xc:black -font Helvetica -pointsize 30 -gravity center \
          -draw "fill white  text  1,1  '$SITENAME'  \
                             text  0,0  '$SITENAME'  \
                 fill black  text -1,-1 '$SITENAME'" \
          +matte $WM_STAMP

# zsfclclmask wstar_bsratio bltopvariab stars experimental1


        for i in sfcwind blwind zsfclclmask wstar_bsratio hglider stars press850 rain1
        do
        # create the combined images
        for j in 0800lst 0900lst 1000lst 1100lst 1200lst 1300lst 1400lst 1500lst 1600lst 1700lst 1800lst 1900lst
        do
            FILENAME_HEAD=$LOCATION/$i.curr.$j.d2.head.png
            FILENAME_BODY=$LOCATION/$i.curr.$j.d2.body.png
            FILENAME_FOOT=$LOCATION/$i.curr.$j.d2.foot.png

            FILENAME_TEMP_ALL=$TMP_LOCATION/$i.curr.$j.temp.d2.png
            FILENAME_TEMP_WATER=$TMP_LOCATION/$i.curr.$j.water.d2.png
            FILENAME_FINAL_ALL=$TMP_LOCATION/$i.curr.$j.combined.d2.png
            FILENAME_RESIZE=$TMP_LOCATION/$i.curr.$j.50pct.d2.png

            echo "Building parameter: $i $j for: $FILENAME_HEAD $FILENAME_BODY $FILENAME_FOOT to: $FILENAME_FINAL_ALL"
            #Join up
            $CONVERT_BIN $FILENAME_HEAD $FILENAME_BODY $FILENAME_FOOT -background White -gravity Center -append $FILENAME_TEMP_ALL
            # Full logo
            $COMPOSITE_BIN -geometry +260+1650 $WM_LOGO $FILENAME_TEMP_ALL $FILENAME_TEMP_WATER
            # Watermark
            $COMPOSITE_BIN -dissolve 18 -tile  /tmp/stamp_mask.png $FILENAME_TEMP_WATER $FILENAME_RESIZE

            $CONVERT_BIN $FILENAME_RESIZE -resize 50%  $FILENAME_FINAL_ALL

            # clear up the images
            rm $FILENAME_TEMP_ALL $FILENAME_RESIZE $FILENAME_TEMP_WATER
        done

        # create the loop images
        echo "Rebuilding loops for parameter: $i"
       $CONVERT_BIN   -delay 90   -loop 0   $TMP_LOCATION/$i.curr.*.combined.d2.png $TARGET_LOCATION/$i.curr.loop.d2.gif

        # clear up the images
        FILENAME_FINAL_ALL=$TMP_LOCATION/$i.curr.*.combined.d2.png
        rm $FILENAME_FINAL_ALL

        done
        # remove WM stamp
        rm -f $WM_STAMP

        echo "Finished normally."