Rubblewebs

THESE CODES ARE PROVIDED FOR AN EXAMPLE OF HOW TO USE IMAGEMAGICK WITH PHP. CARE SHOULD BE TAKEN WHEN ACCEPTING USER INPUT.

I TAKE NO RESPONSABILTY FOR ANY PROBLEMS THAT MAY OCCURE WHEN USING ANY OF THIS CODE.

IT IS UP TO YOU TO SECURE THE CODE AND VALIDATE USER INPUT.

Example of adding a text watermark to an image


OutputInput
The output image Google earth image
     
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