How to extract frames of an animated GIF with PHP

后端 未结 4 594
梦谈多话
梦谈多话 2020-12-05 08:35

I search for a long time how to extract frames from an animated GIF with PHP... unfortunaly I just found how to get their duration...

I really need to extract the GI

4条回答
  •  甜味超标
    2020-12-05 09:17

    I am the author of https://github.com/stil/gif-endec library, which is significantly faster (about 2.5 times) at decoding GIFs than Sybio/GifFrameExtractor library from accepted answer. It has also less memory usage, because it allows you to process one frame after another at decode time, without loading everything to memory at once.

    Small code example:

    decode(function (FrameDecodedEvent $event) {
        /**
         * Write frame images to directory
         */
        $event->decodedFrame->getStream()->copyContentsToFile(
            __DIR__ . "/frames/frame{$event->frameIndex}.gif"
        );
    });
    

提交回复
热议问题