Search code examples
phpanimated-gif

Moving animated gif file using imagegif causes it to lose animation


I have a script that uploads an image using JavaScript, as seen here.

I solved the problem from that post. Now I take the contents from the JavaScript call and save it to a temp_file. After that I resize it, rename etc and save it to a final location.

It works fine until I try to do it with a .gif (I skip all resizing on .gifs).

Here is how I do it:

//$filename = the temp_image that is alredy stored (animated gif)
$this->image = imagecreatefromgif($filename);

header('Content-Type: image/gif');

imagegif($this->image,$savepath);

unlink($filename);

The temp_file is still animated, but after moving it to $savepath it loses its animation.

What could cause this to happen and how can I fix it?


Solution

  • If you're just trying to copy a file from input to output, why parse it?! Just move the file:

    move_uploaded_file($filename, $savepath);