Example of adding a text watermark to an image


OutputInput
The output image Google earth image
<?php
exec
("convert earth.jpg -pointsize 70 -font jd.ttf -fill rgba\(0,0,0,0.4\) \\
-gravity center -annotate +0+0 \"Rubblewebs\" transparent_text.jpg "
);
?>

Code explanationResult
  • earth.jpg Image to read into memory and modifed
  • -pointsize 70 The size of the font
  • -font jd.ttf The font to use. This can be the path to a font or the name of a font installed with ImageMagick. A built in font will not need the extension e.g. -font Helvetica
  • -fill rgba\(0,0,0,0.4\) The colour of the font. In this case it will be a RGB colour ( Black ) using the alpha channel to make it partialy transparent. The first 3 numbers are the red, green, blue and the 4th is the transparency.

    Note: See here for other colour specifications.
    The ( ) need escaping with \

  • -gravity center The position of the text on the background.
  • -annotate +0+0 \"Rubblewebs\" The +0+0 is any offset required from the position set with -gravity and the message to be written. The message must be contained within a pair of " and these need escaping with \
  • transparent_text.jpg "); The name/path to save the final image as
The output image