php 给图片增加背景平铺水印代码
如果你想利用php 给图片增加背景平铺水印效果话,必须利用php的一个插件来实例,就是利用imagick,他可以给图片增加背景平铺水印效果,下面我们提供一款实例代码.
imagemagic官方去除图片背景的命令行模式,代码如下:
- convert -size 140x80 xc:none -fill grey -gravity northwest -draw "text 10,10 'copyright'" -gravity southeast -draw "text 5,15 'copyright'" miff:- | composite -tile - logo.jpg wmark_text_tiled.jpg
imagick代码如下:
- <?php
- $image = new imagick('logo.jpg');
- $im = new imagick();
- $im->newimage( 140, 80, new imagickpixel( "none" ) );
- $draw = new imagickdraw();
- $draw->setfillcolor(new imagickpixel( "grey" ));
- $draw->setgravity(imagick::gravity_northwest);
- $draw->annotation(10,10 ,'copyright');
- $draw->setgravity(imagick::gravity_southeast);
- $draw->annotation(5,15 ,'copyright');
- $im->drawimage( $draw);
- $image = $image->textureimage($im);
- $image->compositeimage($image,imagick::composite_copy,0,0);
- header( "content-type: image/{$image->getimageformat()}" );
- $image->writeimage('wmark_text_tiled.jpg');
- $image->clear();//开源代码phpfensi.com
- $image->destroy();
- ?>