I have an array of pixel data in a JSON object. I’m attempting to use PHP to redraw the pixel data to a GD image.
I’m using something like the following (Notice for testing purposes, I’ve started the index for the loop at 5000, about halfway into the array.)
$im = imagecreate($w,$h);
$i=5000;
while($i < count($pixels)){
$item = $data[$i];
$rgb = $item['rgb'];
$pos = $item['pos'];
$col = imagecolorallocate($im, $rgb[0],$rgb[1],$rgb[2]);
imagesetpixel($im , $pos[0], $pos[1], $col);
$i++;
}
header("Content-Type: image/png");
imagepng($im);
It seems my script is only making it so far down the array before it cuts out and dumps the image out with no error.
Below is the output when I start the array index about halfway thru the length of the array. I get a very small part of the image.

Is this due to memory? Or a timeout? The page doesn’t take long to load or anything…
Ok, for anyone else with this problem. Here’s the fix. Use
imagecreatetruecolorinstead ofimagecreate. It seems thatimagecolorallocatecan only allocate up to 255 colors when usingimagecreate. Whileimagecreatetruecolorhas no such limitation.