使用PHP / GD生成具有“镀金”文本效果的图像

问题描述 投票:0回答:1

我基于用户提供的文本使用PHP 7.3 / GD动态生成PNG图像。

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

Gold-plated effect

知道怎么做到这一点?我找到了应用模糊/发光/阴影的解决方案或通过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);
php gd effects dynamic-image-generation
1个回答
2
投票

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

enter image description here

它不像示例图像,但它有点接近。你必须更多地调整它以获得你想要的东西。

我确实像这样使用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);

所以我基本上用图像来获得金色闪耀。似乎工作,但我认为这可以改进。

© www.soinside.com 2019 - 2024. All rights reserved.