Page 1 of 1

Displaying a loop of generated images

Posted: Wed Aug 12, 2009 12:02 am
by ExpertAlmost
Good morning!

I have some simple test code (below) that generates a random image of 100x100 pixels. I have a loop to generate a new image 25 times. I want to see each of those 25 runs. But this code only shows what may be the last image. What did I do wrong?

How can I automatically update newly generated images in PHP?

Thank you for your expertise!

Code: Select all

<?php
header ("Content-type: image/png");
$ImageSize = 100;
$Img = imagecreatetruecolor($ImageSize, $ImageSize);
for ($Runs = 0; $Runs < 25; $Runs++) {
   for ($XVal = 0; $XVal < $ImageSize; $XVal++) {
      for ($YVal = 0; $YVal < $ImageSize; $YVal++) {
         $RedVal = rand(0, 255); $GreenVal = rand(0, 255); $BlueVal = rand(0, 255); 
         $PixelClr = imagecolorallocate($Img, $RedVal, $GreenVal, $BlueVal);
         imagesetpixel($Img, $XVal, $YVal, $PixelClr);
         imagecolordeallocate($Img, $PixelClr);
         }
      }
      imagepng($Img);
      imagedestroy($Img);
}
?>
 
]

Re: Displaying a loop of generated images

Posted: Wed Aug 12, 2009 2:22 am
by requinix
You can't see more than one image unless
a) You create one big image and copy each one onto a different part - like a mosaic
b) You use an HTML page with lots of <img> tags

Re: Displaying a loop of generated images: Impossible???

Posted: Wed Aug 12, 2009 7:31 am
by ExpertAlmost
Thank you for the kindness of your reply Tasairis!

Perhaps a more detailed description of what I am trying to do is in order. Rather than show 25 images (in a row or column formation), or one big composite image containing the 25 images -- I want to see in one location on one page, a graphic changing 25 times, once for each iteration of generation. Perhaps thinking of it as an animation makes more sense? If the loop is too fast, I can always put in a delay.

Perhaps it is impossible to do this in PHP and all I can do is 25 images in a line?

Thanks again to all of you ExpertsAlready for your help!