水印为GIF动画,用PHP ImageMagick库 [英] Watermark to animated GIF with PHP ImageMagick library

查看:962
本文介绍了水印为GIF动画,用PHP ImageMagick库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经加入PHP水印动画图像,但我所面临的问题的 orginal.gif 图像创建水印后不动画。

I have added PHP watermark animated image but i have faced problem the orginal.gif image is not animated after creating the watermark.

code:

Code:

<?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

orginal.gif

watermark.png

watermark.png

输出:

Output:

说明:我有一个表格有选择上传文件,上传文件只接受gif图片上传后的GIF图像GIF图像将在该网站的标志水印显示。但给水印图像时,水印GIF图像不显示动画。

Description: I have a form there is option to upload file, Upload file only accept gif image after upload the gif image the gif image will show with the logo watermark in the site. But when give watermark image the watermark GIF image is not animated.

推荐答案

你可以试试这个:
    

you can try this :

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

这篇关于水印为GIF动画,用PHP ImageMagick库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆