PHP Imagick文字加阴影(外发光)详解编程语言

PHP Imagick文字加阴影(外发光)


$canvas = new /Imagick();
$canvas->newImage(500, 200, 'white');
$canvas->setImageFormat('png');

$text = new /Imagick();
$text->newImage(500, 200, 'none');
$text->setImageFormat('png');

$draw = new /ImagickDraw();
$draw->setFillColor(new /ImagickPixel('#f00'));
$draw->setFontSize(50);
$draw->annotation(100, 60, 'welcome');
$text->drawImage($draw);

$draw->setFillColor(new /ImagickPixel('#fff'));
$draw->setFontSize(50);
$draw->annotation(100, 120, 'welcome');
$text->drawImage($draw);

$shadow_layer = $text->clone();
$shadow_layer->setImageBackgroundColor(new /ImagickPixel('#555'));
$shadow_layer->shadowImage(80, 0.8, 0, 0);
$shadow_layer->compositeImage($text, /Imagick::COMPOSITE_OVER, 0, 0);
$canvas->compositeImage($shadow_layer, /imagick::COMPOSITE_DEFAULT, 0, 0);
$canvas->writeImage("test_0.jpg"); //直接写入test_0.jpg文件
header("Content-type: image/{$canvas->getImageFormat()}");
echo $canvas->getImageBlob();

ps:
drawImage $text->drawImage($draw); 这个$draw是文字对象 $text可以是图片可以是空白画布
setImageBackgroundColor 设置阴影颜色
shadowImage 第一个参数是透明度0~255 第二个参数就是值越大就是扩散越大 第三和第四就是x和y的阴影位移
compositeImage 这个是合并图片
$shadow_layer->compositeImage($text, Imagick::COMPOSITE_OVER, 0, 0 ); //$text合并到$shadow_layer
$canvas->compositeImage($shadow_layer, imagick::COMPOSITE_DEFAULT, 0, 0); //$shadow_layer 合并到$canvas

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/19057.html

(0)
上一篇 2021年7月19日
下一篇 2021年7月19日

相关推荐

发表回复

登录后才能评论