我需要使用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 –