I posted this problem at another board and haven't recieved a clearcut answer as of yet. Yes, they gave me a few good places to look for the problem, but nothing has helped yet.
I have written a script that writes several lines of text to an image. This is not all that difficult UNTIL I attempted to use an array to change the font for each line of text.
Is it possible with GD to change fonts midstream in this mannor?
Here is my code for testing .....
<?php
Header("Content-type: image/png");
//
$fontpath = realpath('./fonts/');
putenv('GDFONTPATH='.$fontpath);
$imgHgt = 100;
$imgWidth= 400;
$imgColorHex="487239";
$txt = array('This is Text line 1','This is Text line 2','This is Text line 3','This is Text line 4');
$fntSize = array(18,14,12,10);
$fntHex = array('00FF00','FFFFFF','000000','00FF00');
$fntShad = array(1,0,0,0);
$fnt = array('arial','impact','arial','impact'); //THIS DOESNT WORK
$font = "arial"; //THIS WORKS
$background = @imagecreate($imgWidth, $imgHgt) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($background, 0, 0, 254);
$t = count($txt);
$totY = 5;
$i = 0;
while ($i <= $t)
{
//insert title text
if($fntShad[$i] == 1) //I PUT THIS IN TO SEE IF ATLEAST THE FIRST FONT WAS BEING USED
{
//THE FOLLOWING LINE WORKS
//$bbox = imageftbbox($fntSize[$i], 0, $font, $txt[$i], array("linespacing" => 1));
//END LINE WORKS
$bbox = imageftbbox($fntSize[$i], 0, $fnt[$i], $txt[$i], array("linespacing" => 1));
$width = abs($bbox[0]) + abs($bbox[2]); // distance from left to right
$height = abs($bbox[1]) + abs($bbox[5]); // distance from top to bottom
$xcoord = (($imgWidth - $width) / 2) + 2;
$ycoord = $height + $totY + 2;
$int = hexdec("000000");
$arr = array("red" => 0xFF & ($int >> 0x10),
"green" => 0xFF & ($int >> 0x8),
"blue" => 0xFF & $int);
$tcolor = ImageColorAllocate($background, $arr["red"], $arr["green"], $arr["blue"]);
//THE FOLLOWING LINE WORKS
//imagettftext($background, $fntSize[$i], 0, $xcoord, $ycoord, $tcolor, $font, $txt[$i]);
//END WORKS
imagettftext($background, $fntSize[$i], 0, $xcoord, $ycoord, $tcolor, $fnt[$i], $txt[$i]);
$totY = $ycoord + 5;
$i++;
}
else
{
//THE FOLLOWING LINE WORKS
//$bbox = imageftbbox($fntSize[$i], 0, $font, $txt[$i], array("linespacing" => 1));
//END LINE WORKS
$bbox = imageftbbox($fntSize[$i], 0, $fnt[$i], $txt[$i], array("linespacing" => 1));
$width = abs($bbox[0]) + abs($bbox[2]); // distance from left to right
$height = abs($bbox[1]) + abs($bbox[5]); // distance from top to bottom
$xcoord = ($imgWidth - $width) / 2;
$ycoord = $height + $totY;
$int = hexdec($fntHex[$i]);
$arr = array("red" => 0xFF & ($int >> 0x10),
"green" => 0xFF & ($int >> 0x8),
"blue" => 0xFF & $int);
$tcolor = ImageColorAllocate($background, $arr["red"], $arr["green"], $arr["blue"]);
//THE FOLLOWING LINE WORKS
//imagettftext($background, $fntSize[$i], 0, $xcoord, $ycoord, $tcolor, $font, $txt[$i]);
//END WORKS
imagettftext($background, $fntSize[$i], 0, $xcoord, $ycoord, $tcolor, $fnt[$i], $txt[$i]);
$totY = $ycoord + 5;
$i++;
}
}
imagepng($background);
ImageDestroy($background);
?>
The error it throws:
Warning: imageftbbox() [function.imageftbbox]: Could not find/open font in C:\AppServ\www\direct\test.php on line 59
Warning: imagettftext() [function.imagettftext]: Could not find/open font in C:\AppServ\www\direct\test.php on line 74
I look forward to hearing from anyone who can give me some insight on how to accomplish this if it is possible.
Thanks!
Stang 🙂