我需要使用imageMagick为动画GIF添加水印。
但我有一个问题!
我的代码:
使用imageMagick将水印添加到动画GIF(PHP)
<?php
$image = new Imagick();
$image->readImage("orginal.gif");
$watermark = new Imagick();
$watermark->readImage("watermark.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)/2;
$y = ($iHeight - $wHeight)/2;
$image->compositeImage($watermark, imagick::COMPOSITE_OVER, $x, $y);
header("Content-Type: image/" . $image->getImageFormat());
echo $image;
?>
原始GIF:
See Original GIF
输出GIF:
See Output GIF
创建水印后,我的GIF不是动画!
我该如何解决它?
您需要合并图像并将水印应用到每个框架,然后重新组装http://php.net/manual/en/imagick.coalesceimages.php –