php imaging - problem with a simple rectangle
Posted: Wed Apr 30, 2008 5:22 am
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Hi,
I've just started learning the image functions in php. I wanted to create a simple php file, which acts as an image ( header("Content-type: image/png"); ) and which draws a "shading" rectangle, that is a filled rect often used on websites as a background of headers etc.
Anyway - as a start I thought I'll create a function which will draw it with random colors - precisely I was going to draw as many lines as needed, with the colors slowly changing, but as a test these colors are random. Here's my test code:
And here is the result:
http://www.konradp.com/wsystem/images/p ... w_rect.php
As you can see, the rectangle's size is OK - 512x512 but the lines with random colors end up on line 255, the rest is a solid color.
Can somebody explain me why?
And by the way - does imagecreate function create an image with 24 bits or 8 bits color ? (Although it shouldn't change anything regarding my problem).
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Hi,
I've just started learning the image functions in php. I wanted to create a simple php file, which acts as an image ( header("Content-type: image/png"); ) and which draws a "shading" rectangle, that is a filled rect often used on websites as a background of headers etc.
Anyway - as a start I thought I'll create a function which will draw it with random colors - precisely I was going to draw as many lines as needed, with the colors slowly changing, but as a test these colors are random. Here's my test code:
Code: Select all
$width=512;$height=512;
$im=imagecreate($width,$height);//imagecreatetruecolor ?
//drawing horizontal lines from up to down:
for ($i=0;$i<$height;$i++){
$col=imagecolorallocate($im, rand(0,255), rand(0,255), rand(0,255));
imageline($im,0,$i,$width,$i,$col);
//imagecolordeallocate($im, $col); //everything goes wrong if this is on
};
imagepng($im);
imagedestroy($im);
http://www.konradp.com/wsystem/images/p ... w_rect.php
As you can see, the rectangle's size is OK - 512x512 but the lines with random colors end up on line 255, the rest is a solid color.
Can somebody explain me why?
And by the way - does imagecreate function create an image with 24 bits or 8 bits color ? (Although it shouldn't change anything regarding my problem).
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: