Forum Moderators: coopster

Message Too Old, No Replies

animated images and ImageCreateFromgif()

         

PokeTech

2:29 pm on Feb 22, 2009 (gmt 0)

10+ Year Member



I'm hosting some images, some of which are animated and I want be able to display the animated images so that they actually work and just stop on the first frame.

Here's something I'm using:

<?
header("Content-type: image/gif");

$path = "data/" . $_GET['user'] . "/images/" . $_GET['filename'];
$im = ImageCreateFromgif($path);

imagegif($im);
?>

It works fine for images that aren't animated but the images the are just stop on the first frame.

Is there something else I need to do? Any help would be appreciated.

IanKelley

8:01 pm on Feb 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Have you tried reading the file directly and then echoing it with a GIF header?

<? 
$path = "data/" . $_GET['user'] . "/images/" . $_GET['filename'];
$img = fread(fopen($path,'r'),filesize($path));
fclose($path);
header("Content-type: image/gif");
echo $img;
?>

You should of course do some checking to make sure that the user input (from GET) is kosher, and that the file is in fact a valid GIF, before outputting.

[edit: typo]

[edited by: IanKelley at 8:02 pm (utc) on Feb. 22, 2009]

PokeTech

10:09 pm on Feb 22, 2009 (gmt 0)

10+ Year Member



Well I was having a little trouble with the fclose() and changed the code a little but it works now, Thanks!

<?php
$path = "image_location";
$img = fread(fopen($path,'r'),filesize($path));

header("Content-type: image/gif");
echo $img;
?>

Just posted it if anyone needs it.

IanKelley

11:38 pm on Feb 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



My mistake, was typing too fast, $path is not the file handle so it can't be passed to fclose.

whoisgregg

3:44 pm on Feb 23, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If all you want to do is dump the entire file to the output, you can just use readfile [php.net]() instead of all that fread, fopen stuff.