PockyBum522
Programmer
Hello, I'm new to php and working on someone else's code, however I have plenty of experience in programming in other languages. My question is, why does this script that should fill a square png with each pixel being a random color only fill the first 256 pixels?
<?php
$height = 50;
$width = 50;
$cypher_img = imagecreate($width, $height);
$total = $width * $height;
$nowx = 0;
$nowy = 0;
while($nowx * $nowy < $total) {
$red = rand(0, 255);
$green = rand(0, 255);
$blue = rand(0, 255);
$randcolor = ImageColorAllocate($cypher_img, $red, $green, $blue);
imagesetpixel($cypher_img, $nowx, $nowy, $randcolor);
$nowx++;
//imagecolordeallocate ($randcolor, $cypher_img);
if($nowx > $width){$nowy++; $nowx = 0;}
}
header ("Content-type: image/png");
ImagePng ($cypher_img);
ImageDestroy($cypher_img);
?>
Also, why does imagecolordeallocate put errors in the image if you un-remark it at the end there?
Thank you!
<?php
$height = 50;
$width = 50;
$cypher_img = imagecreate($width, $height);
$total = $width * $height;
$nowx = 0;
$nowy = 0;
while($nowx * $nowy < $total) {
$red = rand(0, 255);
$green = rand(0, 255);
$blue = rand(0, 255);
$randcolor = ImageColorAllocate($cypher_img, $red, $green, $blue);
imagesetpixel($cypher_img, $nowx, $nowy, $randcolor);
$nowx++;
//imagecolordeallocate ($randcolor, $cypher_img);
if($nowx > $width){$nowy++; $nowx = 0;}
}
header ("Content-type: image/png");
ImagePng ($cypher_img);
ImageDestroy($cypher_img);
?>
Also, why does imagecolordeallocate put errors in the image if you un-remark it at the end there?
Thank you!