Last active
May 25, 2020 22:04
-
-
Save MahinAbbasianpoor/90c23b25841c415a39d4 to your computer and use it in GitHub Desktop.
repeat watermark image with imagick in php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// load images | |
$image = new Imagick("main_image.jpg"); | |
$watermark = new Imagick("stamp.png"); | |
// main image dimension | |
$geo=$image->getImageGeometry(); | |
$x=$geo['width']; | |
$y=$geo['height']; | |
// stamp image dimension | |
$geo_stamp=$watermark->getImageGeometry(); | |
$sx=$geo_stamp['width']; | |
$sy=$geo_stamp['height']; | |
// repeat stamp image and write it on main image | |
for($i=0;$i<=round($x/$sx)+1;$i++){ | |
for($j=0;$j<=round($y/$sy)+1;$j++){ | |
// compose watermark onto image | |
$image->compositeImage( $watermark, $watermark->getImageCompose(), ($i*$sx), ($j*$sy)); | |
} | |
} | |
// export final image | |
$image->writeImage("main_image_watermark.jpg"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment