使用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();
$image->destroy();
?>
源图片: