php使用imagick给图片加水印的方法
<?php
$image = new Imagick();
$image->readImage("http://phpff.com/original.jpg");
$watermark = new Imagick();
$watermark->readImage("http://php.com/data/mark.png");
// how big are the images?
$iWidth = $image->getImageWidth();
$iHeight = $image->getImageHeight();
$wWidth = $watermark->getImageWidth();
$wHeight = $watermark->getImageHeight();
if ($iHeight < $wHeight || $iWidth < $wWidth) {
// resize the watermark
$watermark->scaleImage($iWidth, $iHeight);
// get new size
$wWidth = $watermark->getImageWidth();
$wHeight = $watermark->getImageHeight();
}
// calculate the position
$x = ($iWidth – $wWidth);
$y = ($iHeight – $wHeight);
$image->compositeImage($watermark, imagick::COMPOSITE_OVER, $x, $y);
header("Content-Type: image/" . $image->getImageFormat());
echo $image;
?>
参考:
https://www.sitepoint.com/watermarking-images/
imagick
http://php.net/manual/en/imagick.construct.php