Watermark Image Guide

Develop your own solution to protect images and photos with custom watermarks by integrating with iLoveIMG’s REST API.

New to the API? Start with Processing an image: every tool guide builds on its task flow.

Basic add a watermark

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

Start taskPHP
// Create a new task
$myTaskWatermark = $iloveimg->newTask('watermark');

// Add files to task for upload
$file1 = $myTaskWatermark->addFile('path/to/file1_name.jpg');

// Add a text watermark element
$element = $myTaskWatermark->addElement();
$element->setText('iLoveIMG');

// Execute the task
$myTaskWatermark->execute();

// Download the package files
$myTaskWatermark->download();
PHP library ilovepdf/iloveimg-phpcomposer require ilovepdf/iloveimg-php

The Watermark tool is composed of 2 different elements that can be configured through the property type: text type adds text watermarks and image type adds image-based watermarks. The image type is limited to PNG and JPG format files no bigger than 1Mb.


There is a list of default settings which can be customized, as you will see later.

Advanced add watermarks

Setting watermark opacity

Setting watermark opacityPHP
// Select watermark parameters
$element = $myTaskWatermark->addElement(['text' => 'iLoveIMG', 'opacity' => 50]);
// Execute the task
$myTaskWatermark->execute();
PHP library ilovepdf/iloveimg-phpcomposer require ilovepdf/iloveimg-php

With opacity you can set the opacity intensity (from 0 to 100, where 100 is fully opaque) of a watermark for both the text (as shown on the code example) and image elements.

Setting watermark position

Setting watermark positionPHP
// Select watermark parameters
$element = $myTaskWatermark->addElement();
$element->setText('iLoveIMG');
$element->setGravity('NorthEast');
// Execute the task
$myTaskWatermark->execute();
PHP library ilovepdf/iloveimg-phpcomposer require ilovepdf/iloveimg-php

gravity places your watermark at different image locations. Accepted values are: North, NorthEast, NorthWest, Center, East, West, South, SouthEast, SouthWest (default Center).


Also, you can define vertical_adjustment_percent and horizontal_adjustment_percent in order to move the element vertically or horizontally having as an origin the selected gravity origin.

Watermark mosaic

Watermark mosaicPHP
// Select watermark parameters
$element = $myTaskWatermark->addElement();
$element->setText('iLoveIMG');
$element->setMosaic(true);
// Execute the task
$myTaskWatermark->execute();
PHP library ilovepdf/iloveimg-phpcomposer require ilovepdf/iloveimg-php

If mosaic is set to true, your watermark will be stamped in a 3x3 mosaic (once at each gravity position).

Watermark rotation

Watermark rotationPHP
// Select watermark parameters
$element = $myTaskWatermark->addElement();
$element->setText('iLoveIMG');
$element->setRotation(30);
// Execute the task
$myTaskWatermark->execute();
PHP library ilovepdf/iloveimg-phpcomposer require ilovepdf/iloveimg-php

rotation will stamp your watermark rotated by the specified number of degrees (clockwise).

Set a watermark font format

Note that this function only works with the text based watermarks. Font settings are ignored for image watermarks.

Set a watermark font formatPHP
// Select watermark parameters
$element = $myTaskWatermark->addElement();
$element->setText('iLoveIMG');
$element->setFontFamily('Courier');
$element->setFontStyle('Bold');
$element->setFontSize(18);
$element->setFontColor('#ffffff');
// Execute the task
$myTaskWatermark->execute();
PHP library ilovepdf/iloveimg-phpcomposer require ilovepdf/iloveimg-php

font_family, font_style, font_size and font_color are properties to customize text font format. The font_family property changes which font will be used, the font_style property changes the text style such as bold or italic, the font_size property changes the font size, and the font_color property changes the color of the watermark text.