我发现创建字体/图像蒙版时需要此方法,并且需要将其设置为 false,否则蒙版将无效。以下是一个示例
<?php
$image = new Imagick('myImage.png');
$watermark = new Imagick();
$mask = new Imagick();
$draw = new ImagickDraw();
$width = $image->getImageWidth();
$height = $image->getImageHeight();
$watermark->newImage($width, $height, new ImagickPixel('grey30'));
$mask->newImage($width, $height, new ImagickPixel('black'));
$text = 'Copyright';
$draw->setFont('Bookman-Demi');
$draw->setFontSize(20);
$draw->setFillColor('grey70');
$draw->setGravity(Imagick::GRAVITY_SOUTHEAST);
$watermark->annotateImage($draw, 10, 12, 0, $text);
$draw->setFillColor('white');
$mask->annotateImage($draw, 11, 13, 0, $text);
$mask->annotateImage($draw, 10, 12, 0, $text);
$draw->setFillColor('black');
$mask->annotateImage($draw, 9, 11, 0, $text);
$mask->setImageMatte(false);
$watermark->compositeImage($mask, Imagick::COMPOSITE_COPYOPACITY, 0, 0);
$image->compositeImage($watermark, Imagick::COMPOSITE_DISSOLVE, 0, 0);
$image->setImageFormat('png');
header('Content-type: image/png');
echo $image;
?>