imagick 加水印 php java 乱码

php代码

$draw=newImagickDraw();

$draw->setFont('C:\\WINDOWS\\Fonts\\simsun.ttc');//必须标明字体

$draw->setFontSize(12);

$file='E:\\images\\11.gif';

$animation=newImagick();//createanimationobject

$animation->setFormat('gif');//setfiletype

$image=newImagick($file);

$ftype=strtolower($image->getImageFormat());

$num=$image->getNumberImages();

$text=iconv('gb2312','utf-8','*********);//只支持utf-8

//$text='**********;

//$draw->setTextEncoding("utf-8");

for($i=0;$i<$num;$i++)

{

$image->setImageIndex($i);

$thisimage=newImagick();

$thisimage->readImageBlob($image);

$delay=$thisimage->getImageDelay();

$thisimage->annotateImage($draw,0,12,0,$text);

$animation->addImage($thisimage);

$animation->setImageDelay($delay);

}

$image->destroy();

$image->clear();

header("Content-Type:image/gif");

echo($animation->getImagesBlob());

java

只需要指定字体即可。

相关推荐