Add watermarks

Welcome to the Add watermarks to image guide. This guide will teach you how add watermarks to image files easily.

Remember that all Tool Guides takes into account that you have previous knowledge about the Basics to process images with our REST API but if not, we strongly recommend you to read the related guide before start with this one.

Basic Add watermarks to images

You can add a watermark to your image files as shown in this code:

Download the PHP library from GitHub

Once created the watermark task and uploaded the desired image file, you need to do is call the addElement() method that will return the object element to stamp over the image. This object is configurable.

OOn the example above we set the watermark as a text, but we can work also with images as a watermark. Let's see all the options:

Advanced Watermark

Text options

Here we can see all text options we can set:

Download the PHP library from GitHub

setFontFamily(), setFontSize() and setFontColor() are functions to customize setText() font format.

  • setFontFamily() can change which font will be used. Allowed values are 'Arial', 'Arial Unicode MS', 'Verdana', 'Courier', 'Times New Roman', 'Comic Sans MS', 'WenQuanYi Zen Hei', 'Lohit Marathi'.
  • setFontStyle() can change the style for the font. Allowed values are 'Regular', 'Normal', 'Bold', 'Italic', 'Bold-Italic'.
  • setFontSize() change the font size. Allowed values are integer numbers.
  • setFontColor() for the text color, with hexadecimal value as string
  • setColorShadow() for the text shadow color, with hexadecimal value as string

Image options

Here we can see all image options we can set:

Download the PHP library from GitHub

You just need to add the file you want to use as image element to stamp as a watermark.

Watermark position

This code shows how to set the watermark position, on both text or image elements.

Download the PHP library from GitHub
  • setGravity() default is 'Center' and allows 'North', 'NorthEast', 'NorthWest', 'Center', 'CenterEast', 'CenterWest', 'East', 'West', 'South', 'SouthEast', 'SouthWest' values.
  • setVerticalPositionAdjustment() and setHorizontalAdjustmentPercent() can set the adjustment based on a percentage of the stamped image.
  • Watermark opacity

    Download the PHP library from GitHub

    opacity(50) will set the opacity intensity of our watermark to 50% even if it’s a text (as it is on the code example) or an image file.

    Watermark size

    Because we can set the watermark to multiple images and we may want all images looks similar, the size will be set in percentage.

    Download the PHP library from GitHub

    In the example above we set the element $watermarkLogo stamped on the 'NorthWest' corner of the image with a size of 20% of the background image.

    Watermark rotation

    Download the PHP library from GitHub

    setRotation(180) will stamp your watermark rotated by 180 degrees.

    Watermark mosaic

    The mosaic option will set 9 elements, one in each gravity position.

    Download the PHP library from GitHub