Re: Re: Images-weird!!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 02 Feb 2003 14:36:38 -0800 (PST)
Mihail Bota <mbota@almaak.usc.edu> 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; $i<17; $i++) {
	for ($j=0; $j<17; $j++) {
		/* should be 0..11 to avoid the test */
		$qq=rand(0,13);
		if($qq && $qq<12){
			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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux