这是我在程序中使用的代码。我正在循环遍历数据库中的每个文本行,但是当我尝试使用2种或更多不同的颜色时,它会混乱。
颜色似乎混淆了。
<?php
include("settings.php");
header("Content-Type: image/jpeg");
$fn = "templates/".getfilename($_GET[tid]);
$im = ImageCreateFromGif($fn);
$qGet = "SELECT * FROM textlines WHERE tid = '$_GET[tid]'";
$rsGet = getSqlQuery($qGet);
while($resGet = getSqlFetch($rsGet))
{
$size = $resGet[size];
$angle = $resGet[angle];
$x = $resGet[x];
$y = $resGet[y];
$color = $resGet[color];
$font = $resGet[font];
$fontfile = "fonts/".getfontfilename($font);
$textvalue = $resGet[textvalue];
//The numbers are the RGB values of the color you want to use
if ($color == "white") { $color = ImageColorAllocate($im, 255, 255, 255); }
if ($color == "black") { $color = ImageColorAllocate($im, 0, 0, 0); }
if ($color == "red") { $color = ImageColorAllocate($im, 255, 0, 0); }
Imagettftext($im, $size, $angle, $x, $y, $color, $fontfile, $textvalue);
}
Imagejpeg($im, '', 100);
ImageDestroy($im);
?>