gif.js js合成gif动画的插件


gif.js js合成gif动画的插件

第一步引入bfwone

第二步执行插件

示例如下

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>BFW NEW PAGE</title>
    <script id="bfwone" type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/bfwone.js"></script>
    <script type="text/javascript">
        bready(function() {
            use(["gif"], function() {
                // console.log(gifs);
                var gifs = new GIF({
                    workers: 2,
                    quality: 10,
                    workerScript: '//repo.bfw.wiki/bfwrepo/js/gif.worker.js'
                });
                // add a image element
                // console.log(gifs);
                var img1 = document.querySelector('#img1');
                var img2 = document.querySelector('#img2');
                var img3 = document.querySelector('#img3');
                var img4 = document.querySelector('#img4');

                gifs.addFrame(img1, {
                    delay: 500
                });
                gifs.addFrame(img2, {
                    delay: 500
                });
                gifs.addFrame(img3, {
                    delay: 500
                });
                gifs.addFrame(img4, {
                    delay: 500
                });

                // or a canvas element
                //  gif.addFrame(canvasElement, {
                //   delay: 200
                //   });

                // or copy the pixels from a canvas context
                // gif.addFrame(ctx, {
                //   copy: true
                //  });
                console.log(gifs);
                gifs.on('finished', function(blob) {
                    console.log("dddd");
                    document.querySelector('#gifresult').src=URL.createObjectURL(blob);
                    ///window.open(URL.createObjectURL(blob));
                    // var el = document.createElement('a');
                    // el.href = URL.createObjectURL(blob);
                    // el.download = 'demo-name'; //设置下载文件名称
                    // document.body.appendChild(el);
                    // var evt = document.createEvent("MouseEvents");
                    // evt.initEvent("click", false, false);
                    // el.dispatchEvent(evt);
                    // document.body.removeChild(el);
                });

                gifs.render();
                console.log(gifs);
            });
        });
    </script>
    <style>

    </style>
</head>
<body>
    <h1>待合成gif的四张图</h1>
    <div class="images">

        <img id="img1" src="//repo.bfw.wiki/bfwrepo/image/anim1.jpg" />
        <img id="img2" src="//repo.bfw.wiki/bfwrepo/image/anim2.jpg" />
        <img id="img3" src="//repo.bfw.wiki/bfwrepo/image/anim3.jpg" />
        <img id="img4" src="//repo.bfw.wiki/bfwrepo/image/anim4.jpg" />

    </div>
    <h1>合成后</h1>
    <div>
        <img id="gifresult" />
    </div>
</body>
</html>


立即下载gif.js查看所有js插件

网友评论0

程序员在线工具箱