使用imagick在动态gif图片上打文字水印
代码如下:
<?php
$imagedraw = new Imagick();
$pixel = new ImagickPixel('gray');
$pixel->setColor('black');
$imagedraw->newImage(100, 75, $pixel);
$draw = new ImagickDraw();
$draw->setFont('Bookman-DemiItalic');
$draw->setFontSize(12);
$image=new Imagick();
$animation = new Imagick();
$animation->setFormat( "gif" );
$image->readImage("old.gif");
$unitl = $image->getImageIndex();
$image->writeImages('animation.gif',false);
$delay = $image->getImageDelay();
$filename = 'animation-';
for ($i=0; $i<$unitl; $i++) {
$thisimage = new Imagick();
$thisimage->readImage($filename.$i.'.gif');
$thisimage->annotateImage($draw, 0, 12, 0, 'copyright by mpeg');
$animation->addImage($thisimage);
$animation->setImageDelay($delay);
}
header("Content-Type: image/gif");
echo $animation->getImagesBlob();
?>
效果图: