This is a good example,您几乎可以使用these functions 完成所有操作。虽然可能,但创建一个像你描述的那样的图像会非常困难,因为我用渐变、循环和颜色做了一些奇怪的东西。
如果您想根据某些参数动态制作这样的图像,您始终可以事先在 Photoshop 中创建图像,然后根据用户选择的内容叠加它们。
您可以享受很多乐趣。
编辑:哦,顺便说一句,如果您有兴趣 giving an invalid parameter shows some of the python code 负责创建图像并导致错误。这是了解代码的好地方。
第二次编辑:这只是我用这种技术所做的事情。请记住,这是很久以前的事了。它接受基于查询字符串的名称,并且基本上会执行一些包含大量随机数的循环。
这是源代码,对于任何愚蠢的代码/引用,我深表歉意。这是很久以前写的,我相信当时我大约 14 岁(可能有很多缺陷)。
<?php
header("Content-type:image/jpeg");
$array=array("I am a monument to all your sins", "Currently making pizza","Best before 12/7/09", "Farming Onions");
function imagettftext_cr(&$im, $size, $angle, $x, $y, $color, $fontfile, $text)
{
// retrieve boundingbox
$bbox = imagettfbbox($size, $angle, $fontfile, $text);
// calculate deviation
$dx = ($bbox[2]-$bbox[0])/2.0 - ($bbox[2]-$bbox[4])/2.0; // deviation left-right
$dy = ($bbox[3]-$bbox[1])/2.0 + ($bbox[7]-$bbox[1])/2.0; // deviation top-bottom
// new pivotpoint
$px = $x-$dx;
$py = $y-$dy;
return imagettftext($im, $size, $angle, $px, $y, $color, $fontfile, $text);
}
$image = imagecreate(500,90);
$black = imagecolorallocate($image,0,0,0);
$grey_shade = imagecolorallocate($image,40,40,40);
$white = imagecolorallocate($image,255,255,255);
$text = $array[rand(0,sizeof($array)-1)];
// Local font files, relative to script
$otherFont = 'army1.ttf';
$font = 'army.ttf';
if($_GET['name'] == ""){ $name = "Sam152";}else{$name= $_GET['name'];}
$name = substr($name, 0, 25);
//BG text for Name
while($i<10){
imagettftext_cr($image,rand(2,40),rand(0,50),rand(10,500),rand(0,200),$grey_shade,$font,$name);
$i++;
}
//BG text for saying
while($i<10){
imagettftext_cr($image,rand(0,40),rand(90,180),rand(100,500),rand(200,500),$grey_shade,$otherFont,$text);
$i++;
}
// Main Text
imagettftext_cr($image,35,0,250,46,$white,$font,$name);
imagettftext_cr($image,10,0,250,76,$white,$otherFont,$text);
imagejpeg($image);
?>