【问题标题】:Generating an image with a "Gold-plated" text effect using PHP/GD使用 PHP/GD 生成带有“镀金”文字效果的图像
【发布时间】:2019-04-14 04:56:03
【问题描述】:

我正在使用 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);

【问题讨论】:

  • 是否应该包括您的示例中的链和连接?这可能是最难创建的部分。
  • @KIKOSoftware 不用,我只需要镀金效果
  • 好的,好吧,阴影并不难,只是把文字写成深色,稍微偏移,然后在上面涂上金色。获得正确的金色光芒会更难。
  • @KIKOSoftware,没错,这里的重点是获得金色光芒
  • 也许是imagelayereffect()?不过我自己从来没有用过。

标签: php gd effects dynamic-image-generation


【解决方案1】:

嗯,我玩了一下,得到了这个:

它与示例图像不完全一样,但已经有些接近了。你必须多花点时间才能得到你想要的。

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

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

【讨论】:

  • 非常感谢。确实还有一些不同,但我同意你的看法,我可以从这里开始调整过滤器/纹理,它应该可以完成这项工作!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-24
  • 2016-06-09
  • 1970-01-01
  • 2020-09-05
  • 1970-01-01
  • 2011-06-14
相关资源
最近更新 更多