- Get started
- Overview
- Getting started
- Processing an image
- Common functions
- Error handling
- Tool guides
-
Compress images
-
Resize images
-
Crop images
-
Convert images
-
Rotate images
-
Watermark images
-
Repair images
Resources
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:
// 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();composer require ilovepdf/iloveimg-phpThe 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
// Select watermark parameters
$element = $myTaskWatermark->addElement(['text' => 'iLoveIMG', 'opacity' => 50]);
// Execute the task
$myTaskWatermark->execute();composer require ilovepdf/iloveimg-phpWith 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
// Select watermark parameters
$element = $myTaskWatermark->addElement();
$element->setText('iLoveIMG');
$element->setGravity('NorthEast');
// Execute the task
$myTaskWatermark->execute();composer require ilovepdf/iloveimg-phpgravity 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
// Select watermark parameters
$element = $myTaskWatermark->addElement();
$element->setText('iLoveIMG');
$element->setMosaic(true);
// Execute the task
$myTaskWatermark->execute();composer require ilovepdf/iloveimg-phpIf mosaic is set to true, your watermark will be stamped in a 3x3 mosaic (once at each gravity position).
Watermark rotation
// Select watermark parameters
$element = $myTaskWatermark->addElement();
$element->setText('iLoveIMG');
$element->setRotation(30);
// Execute the task
$myTaskWatermark->execute();composer require ilovepdf/iloveimg-phprotation 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.
// 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();composer require ilovepdf/iloveimg-phpfont_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.