ardabro
ardabro

Reputation: 2061

Add a tile watermark to a part of the image only

Usually, I add watermark text on documents with something like this:

convert -size 700x360 xc:none -fill "#00000020" -font "Liberation-Sans-Bold" -pointsize 60 \
      -gravity NorthWest -draw "text 0,75 \"${3}\"" \
      -gravity SouthEast -draw "text 0,75 \"${3}\"" \
      miff:- |\
      composite -tile - "${1}" "${2}"

It spreads a tile with text over the whole image.

Now I need to add a watermark that excludes a specific area on the document. My question is: How to limit "operating area" only to a specific rectangular image region defined as x,y,width,height? On the other hand: Is it possible and how to exclude a specific rectangular region and spread my tiles only outside of it?

Upvotes: 0

Views: 433

Answers (1)

fmw42
fmw42

Reputation: 53164

You can do that as follows in Imagemagick by creating a tiled watermark image of the size you want and then compositing over the background image.

Here I create the tile image (mpr:wm) . Then tile it out with a transparent background using -draw "color 0,0 reset". Then I composite that over the background image at the desired upper left corner (+32+32). This is all done in one convert command line without needing to pipe.

In:

enter image description here

in="mandril3.jpg"
out="mandril3_wm.jpg"
text="Testing"
convert -size 64x64 xc:none -fill black \
-font "candice" -pointsize 14 \
-gravity NorthWest -draw "text 0,5 '$text'" \
-gravity SouthEast -draw "text 0,5 '$text'" \
-write mpr:wm +delete \
-size 128x128 xc:none -tile mpr:wm -draw "color 0,0 reset" \
$in +swap -geometry +32+32 \
-compose over -composite \
$out   

Out:

enter image description here

Upvotes: 1

Related Questions