Composite with tile (watermark)

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
Pacio

Composite with tile (watermark)

Post by Pacio »

Hey,

I'm trying to do a simple watermarking script, so I can secure images on my site from stealing.
Here is a site with the effect I would like to achieve: http://www.selonen.org/arto/netbsd/watermarks.html
He's using:

Code: Select all

composite -dissolve 15 -tile watermark.png src.jpg dst.jpg
How can I get the same result with PHP?

I created a PNG transparent image on my own, but can't tile it on the original image.

Thanks in advance

Regards
Pacio


*EDIT*
How I solved it:

Code: Select all

$main = new Imagick('src.jpg');
$watermark = new Imagick('watermark.png');

$watermark_width = $watermark->getImageWidth();
$watermark_height = $watermark->getImageHeight();

$rows = ceil($main->getImageWidth() / $watermark_width);
$cols = ceil($main->getImageHeight() / $watermark_height);

for ( $w=0; $w <= $rows; $w++ ) {
	for ( $h=0; $h <= $cols; $h++ ) {
		$main->compositeImage($watermark, imagick::COMPOSITE_DEFAULT, $w*$watermark_width, $h*$watermark_height);
	}
}

$main->writeImage('dst.jpg');
I had to change PNG layer opacity to about 30%.
Post Reply