{"id":705,"date":"2015-05-16T18:53:01","date_gmt":"2015-05-16T17:53:01","guid":{"rendered":"http:\/\/blog.stratus.org.uk\/?p=705"},"modified":"2020-12-16T19:37:24","modified_gmt":"2020-12-16T19:37:24","slug":"adding-a-watermark-to-an-image","status":"publish","type":"post","link":"https:\/\/blog.stratus.org.uk\/?p=705","title":{"rendered":"Adding a Watermark to an Image"},"content":{"rendered":"\r\n<p class=\"wp-block-paragraph\">This is a common need \u2013 how do I add a watermark to an image I have created?<\/p>\r\n<p>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.<br \/><br \/>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.<\/p>\r\n<pre>#!\/bin\/sh\r\n# Script to add watermark on images\r\nCONVERT_BIN=\/usr\/bin\/convert\r\nCOMPOSITE_BIN=\/usr\/bin\/composite\r\n\r\nif [ \"$1\" != \"\" ]; then\r\n\r\n        HOMEDIR=\/home\/rasp\r\n        TARGETREGION=$1\r\n        LOCATION=$HOMEDIR\/$TARGETREGION\/HTML\/$TARGETREGION\/FCST\r\n        TMP_LOCATION=\/tmp\r\n        TARGET_LOCATION=$HOMEDIR\/$TARGETREGION\/HTML\/$TARGETREGION\/FCST\r\n        SITENAME=<your sitename here>\r\n        WM_LOGO=$HOMEDIR\/water-mark-logo.png\r\n        WM_STAMP=\/tmp\/stamp_mask.png\r\n        echo $HOMEDIR\r\n        echo $TARGETREGION\r\n        echo $LOCATION\r\n        echo $TARGET_LOCATION\r\n        echo $SITENAME\r\nelse\r\n        echo \"Provide a region to sync\"\r\nfi\r\n\r\n        rm -f $WM_STAMP\r\n\r\n  $CONVERT_BIN -size 553x213 xc:black -font Helvetica -pointsize 30 -gravity center \\\r\n          -draw \"fill white  text  1,1  '$SITENAME'  \\\r\n                             text  0,0  '$SITENAME'  \\\r\n                 fill black  text -1,-1 '$SITENAME'\" \\\r\n          +matte $WM_STAMP\r\n\r\n# zsfclclmask wstar_bsratio bltopvariab stars experimental1\r\n\r\n\r\n        for i in sfcwind blwind zsfclclmask wstar_bsratio hglider stars press850 rain1\r\n        do\r\n        # create the combined images\r\n        for j in 0800lst 0900lst 1000lst 1100lst 1200lst 1300lst 1400lst 1500lst 1600lst 1700lst 1800lst 1900lst\r\n        do\r\n            FILENAME_HEAD=$LOCATION\/$i.curr.$j.d2.head.png\r\n            FILENAME_BODY=$LOCATION\/$i.curr.$j.d2.body.png\r\n            FILENAME_FOOT=$LOCATION\/$i.curr.$j.d2.foot.png\r\n\r\n            FILENAME_TEMP_ALL=$TMP_LOCATION\/$i.curr.$j.temp.d2.png\r\n            FILENAME_TEMP_WATER=$TMP_LOCATION\/$i.curr.$j.water.d2.png\r\n            FILENAME_FINAL_ALL=$TMP_LOCATION\/$i.curr.$j.combined.d2.png\r\n            FILENAME_RESIZE=$TMP_LOCATION\/$i.curr.$j.50pct.d2.png\r\n\r\n            echo \"Building parameter: $i $j for: $FILENAME_HEAD $FILENAME_BODY $FILENAME_FOOT to: $FILENAME_FINAL_ALL\"\r\n            #Join up\r\n            $CONVERT_BIN $FILENAME_HEAD $FILENAME_BODY $FILENAME_FOOT -background White -gravity Center -append $FILENAME_TEMP_ALL\r\n            # Full logo\r\n            $COMPOSITE_BIN -geometry +260+1650 $WM_LOGO $FILENAME_TEMP_ALL $FILENAME_TEMP_WATER\r\n            # Watermark\r\n            $COMPOSITE_BIN -dissolve 18 -tile  \/tmp\/stamp_mask.png $FILENAME_TEMP_WATER $FILENAME_RESIZE\r\n\r\n            $CONVERT_BIN $FILENAME_RESIZE -resize 50%  $FILENAME_FINAL_ALL\r\n\r\n            # clear up the images\r\n            rm $FILENAME_TEMP_ALL $FILENAME_RESIZE $FILENAME_TEMP_WATER\r\n        done\r\n\r\n        # create the loop images\r\n        echo \"Rebuilding loops for parameter: $i\"\r\n       $CONVERT_BIN   -delay 90   -loop 0   $TMP_LOCATION\/$i.curr.*.combined.d2.png $TARGET_LOCATION\/$i.curr.loop.d2.gif\r\n\r\n        # clear up the images\r\n        FILENAME_FINAL_ALL=$TMP_LOCATION\/$i.curr.*.combined.d2.png\r\n        rm $FILENAME_FINAL_ALL\r\n\r\n        done\r\n        # remove WM stamp\r\n        rm -f $WM_STAMP\r\n\r\n        echo \"Finished normally.\"\r\n\r\n<\/pre>\r\n\r\n<p>\u00a0<\/p>","protected":false},"excerpt":{"rendered":"<p>This is a common need \u2013 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 &hellip; <a href=\"https:\/\/blog.stratus.org.uk\/?p=705\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18,19],"tags":[],"class_list":["post-705","post","type-post","status-publish","format-standard","hentry","category-programming","category-rasp"],"_links":{"self":[{"href":"https:\/\/blog.stratus.org.uk\/index.php?rest_route=\/wp\/v2\/posts\/705","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.stratus.org.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.stratus.org.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.stratus.org.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.stratus.org.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=705"}],"version-history":[{"count":4,"href":"https:\/\/blog.stratus.org.uk\/index.php?rest_route=\/wp\/v2\/posts\/705\/revisions"}],"predecessor-version":[{"id":710,"href":"https:\/\/blog.stratus.org.uk\/index.php?rest_route=\/wp\/v2\/posts\/705\/revisions\/710"}],"wp:attachment":[{"href":"https:\/\/blog.stratus.org.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.stratus.org.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=705"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.stratus.org.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}