PHP - Create simple animated GIF from two JPEG images?

后端 未结 3 1308
梦如初夏
梦如初夏 2020-12-03 00:00

Does anyone know if it\'s possible to generate an animated GIF from two different JPEG files, displaying one image for x seconds then the other, and so on..?

Any adv

3条回答
  •  悲哀的现实
    2020-12-03 00:46

    This cannot be done with GD but I found a great library for it. It is a bit complicated though, so here is a link to the library which makes animated gifs with php. It explains how to use it thoroughly. http://www.phpclasses.org/package/3163-PHP-Generate-GIF-animations-from-a-set-of-GIF-images.html

    Select 2 pictures and write 100 for speed 900 for width and height. It will put them in an animated gif slideshow.

    Here is the code for that script:

     $error)
        {
            if ($error == UPLOAD_ERR_OK)
            {
                $tmp_name = $_FILES["images"]["tmp_name"][$key];
                $im = imagecreatefromstring(file_get_contents($tmp_name));
                $resized = imagecreatetruecolor($_POST['width'],$_POST['height']);
                imagecopyresized($resized, $im, 0, 0, 0, 0, $_POST['width'], $_POST['height'], imagesx($im), imagesy($im));
                frame($resized);
            }
        }
        $gif = new GIFEncoder($frames,$framed,0,2,0,0,0,'bin');
        echo $gif->GetAnimation();
    }
    ?>
    

    As you see it references the GIFEncoder class found on the first link. It also uses some javascript validation and jQuery multiupload.

    Note: this question has already been asked.

提交回复
热议问题