Marko Mikulić Marko Mikulić - 1 year ago 478
PHP Question

Image watermark in Yii2

I am using yii\imagine\Image extension and want to add a watermark to my image.

Here's my code:

$watermarkImage = '@webroot/../images/watermark.png';
$image = '@webroot/../slike/img-4.jpg';
Image::watermark($image, $watermarkImage);

After this code is executed, nothing happens. What am I missing here?

Answer Source

The ::watermark() function creates the new image but doesn't automatically saves it. The function returns a Imagine\Gd\Image object. This object can be used to save the new files.

$watermarkImage = '@webroot/../images/watermark.png';
$image = '@webroot/../slike/img-4.jpg';
// Store the Image object in a variable
$newImage = Image::watermark($image, $watermarkImage);
// Call the save function to write the file to the disk.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download