Displaying a loop of generated images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ExpertAlmost
Forum Commoner
Posts: 41
Joined: Mon Oct 20, 2008 12:26 am

Displaying a loop of generated images

Post 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);
}
?>
 
]
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Displaying a loop of generated images

Post 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
ExpertAlmost
Forum Commoner
Posts: 41
Joined: Mon Oct 20, 2008 12:26 am

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

Post 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!
Post Reply