views:

686

answers:

3

Let's say that I have a Flash website where you could create an avatar and some motion.

Is there a way to save those into an animated GIF with a server-side language ? (php is preferred)

I've looked around and all I've got are ways to do that with the Flash software itself. Has anybody tried this ?

Thanks in advance.

+1  A: 

Interesting question. It should be possible to send the frames of the animation as bitmapdata to the server and assemble an animated gif on the server. You propably want the animation to be quite short and the resolution pretty low for this to work well.

Some starting points:

Kristian J.
+1  A: 

It depends on exactly how you create the avatar in Flash. By coincidence, my group developed a demo application which does just like that. It is called FunIcons, you can select a character and then create an animation by drawing a path on the face with the mouse (press and hold the mouse button to do so), and then by clicking on the "Save" button, you will get an animated gif with the sequence you just plotted.

The trick is simple: a PHP script on the server side takes the sequence of GIF files that build up the animation, and constructs an animated GIF from them. Here's the script itself:

<?php
    header ("Content-type: image/gif");
    header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    // Date in the past
    header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); 
    header ("Cache-Control: no-cache, must-revalidate");  // HTTP/1.1
    header ("Pragma: no-cache");                          // HTTP/1.0
    header ("Content-Disposition: attachment; filename=\"funicons.gif\"");

    require_once "GifBuilder/GIFEncoder.class.php";

    $path = "http://" . $_SERVER["HTTP_HOST"] . $_SERVER["PHP_SELF"];
    $i = strrpos($path, "/");
    $path = substr($path, 0, $i+1);

    $images = split(",", $_REQUEST["images"]);
    $prevUrl = "";
    while (list ($key, $val) = each($images))
    { 
     if (substr($val, 0, strlen($path)) == $path) $val = substr($val, strlen($path)); 
       if ($val == $prevUrl)
     {
      $delay[count($delay)-1] += 10;
     } else {
      $frames[] = file_get_contents($val);
      $delay[] = 10;
      $prevUrl = $url;
     }
     @set_time_limit(30);
    }
    $gif = new GIFEncoder ( $frames, $delay, 0, 2, -1, -1, -1, "bin" );
    print($gif->GetAnimation());
?>
David Hanak
+2  A: 

Try:

AS3 GIF Animation Encoding Class 0.1 [ by Thibault Imbert ]

http://www.bytearray.org/?p=93

Iain
Thanks, it looks good.
andyk