簡體   English   中英

使用PHP / GD生成具有“鍍金”文字效果的圖像

[英]Generating an image with a “Gold-plated” text effect using PHP/GD

我正在根據用戶提供的文本使用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);

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

在此處輸入圖片說明

它與示例圖像不完全相同,但是越來越接近。 您將不得不花更多時間來獲得您想要的東西。

我確實像這樣使用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);

所以我基本上使用圖像來獲得金色的光芒。 似乎可以工作,但是我認為可以改進。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM