使用PHP ImageMagick库将水印添加到动画GIF中

时间:2014-02-04 14:02:25

标签: php image animation animated-gif watermark

我添加了PHP水印动画图片,但我遇到了问题,orginal.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;
?>

orginal.gif

enter image description here

watermark.png

enter image description here

输出:

enter image description here

说明:我有一个表单,有上传文件的选项,上传文件只接受gif图片上传gif图片后,gif图片会显示网站上的徽标水印。但是当给出水印图像时,水印GIF图像不是动画的。

1 个答案:

答案 0 :(得分:0)

你可以试试这个:     

//use imagemagick command-line
passthru("convert -coalesce orginal.gif -gravity SouthEast -draw 'Image Over 10,10,0,0    $watermark.png' Output.gif");