0

I need to create a php code to show a media gallery, in which each image is shown for some seconds. In particular, the images can be PNG or GIF, and in the second case I need it to show the animation. Basically, my simple code for showing a single PNG image is the following:

<?php

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Content-type: image/png");

$imgpath = "./try.png"

$im = imagecreatefrompng($imgpath);
imagepng($im);
imagedestroy($im);

?>

First, I noticed that if I want to show a GIF image, using the functions imagecreatefromgif() and imagegif(), it only shows the first frame of the animation, and this is the first problem. Secondly, I would ask you what functions I should use if I have a folder with some images (let them be firstly just PNGs) and show them in loop with a regular time interval. The final result, then would be to make this slideshow with PNGs and GIFs in the folder, with the code showing the GIFs as animations. Thank you

Andrea
  • 41
  • 5
  • 1
    I'm not clear why you are trying to make a slideshow in server-side PHP rather than client-side JS? – Chris Haas May 08 '23 at 14:43
  • @ChrisHaas I'm doing this with PHP because I also need to overlap to each image a bar with some data that are renewed each time the php page gets updated. I can do this using the functions imagefilledrectangle(), bbox(), imagettftext(), image copy(). Basically I don't know if this is achievable with some JS code. The data bar is similar to that you can see in this case: http://www.romaeurmeteo.it/foscam/FI9900P_00626E856BBD/snap/webcam.php – Andrea May 08 '23 at 15:00
  • Thanks, that helps. This script that you've posted appears to be focused on processing a single image. The fact that it might be used in a slideshow isn't related to the problem, right? If so I'd search for "PHP animated gif watermark" to get some solutions such as this: https://stackoverflow.com/a/10533113/231316 – Chris Haas May 08 '23 at 15:19
  • @ChrisHaas the idea is to make a loop in which there is a code like that I posted, which shows all the images in the folder, that will have extensions .png or .gif, and overlap to each of them a bar with data. So, what I'm asking is a suggestion of which functions I can use to make this temporized loop (let it be 60 s per img) and how to show the animation inside the .gifs (instead of the single frame that is what it does by default). I'm not sure if I can run a code with shell commands, because the php is hosted on a third party server which I don't control. – Andrea May 13 '23 at 16:52

0 Answers0