【问题标题】:Add watermark to animated GIF with imageMagick (PHP)使用 imageMagick (PHP) 为动画 GIF 添加水印
【发布时间】:2016-12-14 04:12:23
【问题描述】:

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

【问题讨论】:

标签: php imagemagick gif imagick


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2014-02-28
    • 2018-01-09
    • 2021-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多