0

我正在根据用户提供的文本使用PHP 7.3/GD动态生成 PNG 图像。

一切都按预期工作,但我想应用某种过滤器/效果来获得镀金风格,如下所示:

镀金效果

知道如何实现这一目标吗?我找到了应用模糊/发光/阴影或通过 HTML5/CSS3 解决此问题的解决方案,但我必须为这个项目使用 GD/PHP。

这是我当前的代码:

<?php

putenv('GDFONTPATH='.realpath('.'));
header('Content-Type: image/png');
$im = imagecreatetruecolor(300, 200);
$bg = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg);
$gold = imagecolorallocate($im, 255, 215, 0);
imagettftext($im, 28, 0, 76, 110, $gold, 'HirukoBlackAlternate.ttf', 'Stack');
imagepng($im);
imagedestroy($im);
4

1 回答 1

2

好吧,我玩了一下,得到了这个:

在此处输入图像描述

它与示例图像不完全一样,但已经有些接近了。你将不得不多摆弄它才能得到你想要的东西。

我确实像这样使用imagelayereffect()

// start with your code
putenv('GDFONTPATH='.realpath('.'));
header('Content-Type: image/png');
$im = imagecreatetruecolor(300, 200);
$bg = imagecolorallocate($im, 255, 255, 255);
imagefill($im, 0, 0, $bg);

// first the back drop 
$gray = imagecolorallocate($im, 80, 80, 80);
imagettftext($im, 28, 0, 76+3, 110+2, $gray, 'HirukoBlackAlternate.ttf', 'Stack');

// then the gold
$gold = imagecolorallocate($im, 180, 180, 150);
imagettftext($im, 28, 0, 76, 110, $gold, 'HirukoBlackAlternate.ttf', 'Stack');

// get a pattern image
$pattern = imagecreatefromjpeg('http://i.pinimg.com/736x/96/36/3c/96363c9337b2d1aad24323b1d9efda72--texture-metal-gold-texture.jpg');

// copy it in with a layer effect
imagelayereffect($im, IMG_EFFECT_OVERLAY);
imagecopyresampled($im, $pattern, 0, 0, 0, 0, 300, 200, 736, 552);

// output and forget
imagepng($im);
imagedestroy($im);
imagedestroy($pattern);

所以我基本上使用图像来获得金色的光芒。似乎有效,但我认为这可以改进。

于 2019-04-13T20:56:03.820 回答