[PHP-DB] Re: Images-weird!!
Hi Mihai, Didn't try your code, but noticed your comment on colours. RBG values go from 0 - 255, not 1 - 256, so this may be your problem. Adam
[PHP-DB] Re: Images-weird!!
No, this is not the problem. $i and $j start from 0, anyway. The real problem, as I see it, is the following: I have a big loop, to create something like a checkerboard, but with 13 or so colors. If the loop iterates more than 256 times, then those cells with indexes bigger than 255 (or 256, does not matter) will have a single color: that of the 255th or 256th cell. It is as if I do not have only 13 colors, but 256! Try to run the code and see what I mean. Now I try to do my job by using JPGraph, but I succeded to ruin everything:) Oh, dear:) On Mon, 3 Feb 2003, Adam Royle wrote: Hi Mihai, Didn't try your code, but noticed your comment on colours. RBG values go from 0 - 255, not 1 - 256, so this may be your problem. Adam -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Images-weird!!
On Sun, 02 Feb 2003 14:36:38 -0800 (PST) Mihail Bota [EMAIL PROTECTED] wrote: No, this is not the problem. I did not test your code but a color channel start at 0 and finished at 255, corresponding to 256 possibilities. pierre -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Images-weird!!
On Sun, 02 Feb 2003 14:36:38 -0800 (PST) Mihail Bota [EMAIL PROTECTED] wrote: No, this is not the problem. $i and $j start from 0, anyway. The real problem, as I see it, is the following: I have a big loop, to create something like a checkerboard, but with 13 or so colors. If the loop iterates more than 256 times, then those cells with indexes bigger than 255 (or 256, does not matter) will have a single color: that of the 255th or 256th cell. Random color, you create a palette based image, which has only 256 colors (0..255), the 1st allocated color is the backgroud color, you have only 255 colors to use, 1..255. You loop 16*16 (17), you reached the maximum amount of color at the 16th iteration. You can easily solve your problem by using a truecolor image, make your script a little bit more efficient by allocating before the loop, and cleaner without the ugly if else endless test. Find a quick cleanup at the footer As a side note, an image of 500x400 means a horizantal ranges from 0 to 499 and a vertical range from 0 to 399. hth pierre ?php $image=imagecreatetruecolor(500,500); $white=imageColorAllocate($image,255,255,255); imageFilledRectangle($image,0,0,499,499,$white); $colors = array( imagecolorallocate($image, 255, 255, 0), imagecolorallocate($image, 255, 0, 0), imagecolorallocate($image, 255, 0, 100), imagecolorallocate($image, 255, 100, 100), imagecolorallocate($image, 255, 210, 100), imagecolorallocate($image, 0, 255, 255), imagecolorallocate($image, 0, 255, 200), imagecolorallocate($image, 0, 100, 255), imagecolorallocate($image, 0, 100, 200), imagecolorallocate($image, 200, 0, 0), imagecolorallocate($image, 0, 0, 138), imagecolorallocate($image, 0, 0, 255) ); for ($i=0; $i17; $i++) { for ($j=0; $j17; $j++) { /* should be 0..11 to avoid the test */ $qq=rand(0,13); if($qq $qq12){ imagefilledrectangle($image, 7*$j,7*$i,7*$j+7,7*$i+7,$colors[$qq]); } } } header(Content-type: image/png); imagepng($image); imagedestroy($image); ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Images-weird!!
Yeah, I had the idea with truecolor, but I do not have GD2 installed. I have to install it, first. Still, I do not understand! I only have 13 colors, why is allocating only 255? I am not using the indexes in the color allocation. Thanks. On Mon, 3 Feb 2003, Pierre-Alain Joye wrote: On Sun, 02 Feb 2003 14:36:38 -0800 (PST) Mihail Bota [EMAIL PROTECTED] wrote: No, this is not the problem. $i and $j start from 0, anyway. The real problem, as I see it, is the following: I have a big loop, to create something like a checkerboard, but with 13 or so colors. If the loop iterates more than 256 times, then those cells with indexes bigger than 255 (or 256, does not matter) will have a single color: that of the 255th or 256th cell. Random color, you create a palette based image, which has only 256 colors (0..255), the 1st allocated color is the backgroud color, you have only 255 colors to use, 1..255. You loop 16*16 (17), you reached the maximum amount of color at the 16th iteration. You can easily solve your problem by using a truecolor image, make your script a little bit more efficient by allocating before the loop, and cleaner without the ugly if else endless test. Find a quick cleanup at the footer As a side note, an image of 500x400 means a horizantal ranges from 0 to 499 and a vertical range from 0 to 399. hth pierre ?php $image=imagecreatetruecolor(500,500); $white=imageColorAllocate($image,255,255,255); imageFilledRectangle($image,0,0,499,499,$white); $colors = array( imagecolorallocate($image, 255, 255, 0), imagecolorallocate($image, 255, 0, 0), imagecolorallocate($image, 255, 0, 100), imagecolorallocate($image, 255, 100, 100), imagecolorallocate($image, 255, 210, 100), imagecolorallocate($image, 0, 255, 255), imagecolorallocate($image, 0, 255, 200), imagecolorallocate($image, 0, 100, 255), imagecolorallocate($image, 0, 100, 200), imagecolorallocate($image, 200, 0, 0), imagecolorallocate($image, 0, 0, 138), imagecolorallocate($image, 0, 0, 255) ); for ($i=0; $i17; $i++) { for ($j=0; $j17; $j++) { /* should be 0..11 to avoid the test */ $qq=rand(0,13); if($qq $qq12){ imagefilledrectangle($image, 7*$j,7*$i,7*$j+7,7*$i+7,$colors[$qq]); } } } header(Content-type: image/png); imagepng($image); imagedestroy($image); ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Images-weird!!
On Sun, 02 Feb 2003 15:29:44 -0800 (PST) Mihail Bota [EMAIL PROTECTED] wrote: Yeah, I had the idea with truecolor, but I do not have GD2 installed. I have to install it, first. Still, I do not understand! I only have 13 colors, why is allocating only 255? I am not using the indexes in the color allocation. palette based image (imagecreate) can use a maximum of 256 colors. You allocate a new color in each iteration of the inside loop, 16*16=256 and greater than 255, do not forget you have already one color allocated for the background color, btw, you do no need to draw a white box with a palette image, the 1st allocated color is the background color. hth pierre -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Images-weird!!
Got it. Thanks a lot, guys! On Mon, 3 Feb 2003, Pierre-Alain Joye wrote: On Sun, 02 Feb 2003 15:29:44 -0800 (PST) Mihail Bota [EMAIL PROTECTED] wrote: Yeah, I had the idea with truecolor, but I do not have GD2 installed. I have to install it, first. Still, I do not understand! I only have 13 colors, why is allocating only 255? I am not using the indexes in the color allocation. palette based image (imagecreate) can use a maximum of 256 colors. You allocate a new color in each iteration of the inside loop, 16*16=256 and greater than 255, do not forget you have already one color allocated for the background color, btw, you do no need to draw a white box with a palette image, the 1st allocated color is the background color. hth pierre -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php