Image Color Allocate Problem
Posted: Thu Jun 17, 2004 5:47 am
Hi there,
I have stored R, G, B values; size; and the text in the database.
I am able to display the text on the image, but after some rows the function imagecolorallocate returns -1 and hence failing to allocate the color according to the RGB values from database.
So when $tc = -1 in the following code, all the text after some number of rows are of same color.
What could be the reason?
Here is my code.
Hope someone will throw some light on this topic.
Kevin.
I have stored R, G, B values; size; and the text in the database.
I am able to display the text on the image, but after some rows the function imagecolorallocate returns -1 and hence failing to allocate the color according to the RGB values from database.
So when $tc = -1 in the following code, all the text after some number of rows are of same color.
What could be the reason?
Here is my code.
Code: Select all
<?php
include 'connection.php';
$cid = mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
header ("Content-type: image/png");
$im = imagecreate(400, 300);
$bgc = imagecolorallocate($im, 0, 0, 0);
imagecolortransparent($im, $bgc);
$tc = imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
$sql_imginf = "select * from db";
$r_imginf = mysql_db_query($DBName,"$sql_imginf",$cid);
$n_imginf = mysql_num_rows($r_imginf);
for ($i=0;$i<$n_imginf;$i++)
{
//here following function returns -1 after say 25 rows approx.
$tc = imagecolorallocate($im, mysql_result($r_imginf,$i,"r"), mysql_result($r_imginf,$i,"g"), mysql_result($r_imginf,$i,"b"));
imagettftext($im, 15, 0, rand(0,100), rand(0,250), $tc, "fonts/1.ttf", mysql_result($r_imginf,$i,"text"));
}
imagecolortransparent($im, $bgc);
imagepng($im,"images/007.png");
ImageDestroy($im);
?>Kevin.