使用imageMagick(PHP)将水印添加到动画GIF

时间:2016-08-08 11:40:23

标签: php imagemagick gif imagick

我需要使用imageMagick为动画GIF添加水印 但我有一个问题!

我的代码:

<?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没有动画! 我该如何解决?

1 个答案:

答案 0 :(得分:1)

您刚刚找到了一些代码来为图像添加水印。使用动画,您需要将每个帧分开,为其添加水印并将其重新组合在一起。查看:coalesce