Php Gd库图像样式imagettftext
如何制作这样的图像? 我只是想学习如何使用GD库获得这样的输出, 谢谢你们的帮助 下面是一个例子:Php Gd库图像样式imagettftext,php,gd,Php,Gd,如何制作这样的图像? 我只是想学习如何使用GD库获得这样的输出, 谢谢你们的帮助 下面是一个例子: header('Content-Type:image/png');//设置内容类型 $file=“yourmage.png”; $image=imagecreatefrompng($file);//创建图像 $font=“YourFont.ttf”; $size=15//像素 $color=imagecolorallocate($image,255,255)//白色 $text=“此处显示您的文字
header('Content-Type:image/png');//设置内容类型
$file=“yourmage.png”;
$image=imagecreatefrompng($file);//创建图像
$font=“YourFont.ttf”;
$size=15//像素
$color=imagecolorallocate($image,255,255)//白色
$text=“此处显示您的文字”
imagettftext($image,15,0,20,40,$color,$font,$code);//添加文本
imagepng($image);//输出图像
有关更多信息,请参阅
编辑:使用多个imagettftext()
的示例:
header('Content-Type:image/png');//设置内容类型
$file=“yourmage.png”;
$image=imagecreatefrompng($file);//创建图像
$font=“YourFont.ttf”;
$size=15//像素
$color=imagecolorallocate($image,255,255)//白色
$text=“此处显示您的文字”
imagettftext($image,15,0,20,40,$color,$font,$code);//添加文本
$text=“text 2”;
imagettftext($image,15,0,25,45,$color,$font,$code);//添加文本
$text=“text 3”;
imagettftext($image,15,0,30,50,$color,$font,$code);//添加文本
imagepng($image);//输出图像
这是您的代码,您可以在谷歌tho上轻松找到它
<?php
header ("Content-type: image/png");
$string = "your text"; // Change this text
$font = 4; // try changing this as well
$width = imagefontwidth($font) * strlen($string) ;
$height = imagefontheight($font) ;
$im = imagecreatefrompng("/path/to/yourimagefile");
$x = imagesx($im) - $width ;
$y = imagesy($im) - $height;
$backgroundColor = imagecolorallocate ($im, 255, 255, 255);
$textColor = imagecolorallocate ($im, 0, 0,0);
imagestring ($im, $font, $x, $y, $string, $textColor);
imagepng($im);
?>
谢谢你的回答:以下是我的意思,我如何设置每个字母的含义。。样本R-放松O-顺从B-像图中一样明亮。。谢谢。@RobRayo只需多次使用imagettftext
。@RobRayo查看示例。使用imagettftext
任意数量,只需更改位置、文本等。是的,我知道该功能。。如何检测名称的每个字母以及字母的每个含义,这与GD库无关,您应该用PHP解析名称,并从数据库中为每个字母获取一个单词。所以你应该有一个字母和意思的数据库。比如C->聪明的S->愚蠢的等等。当你解析名字时,你会询问每个字母的意思。