omggif icon indicating copy to clipboard operation
omggif copied to clipboard

example browser script

Open mnutt opened this issue 6 years ago • 7 comments

This library works great but there were a few gotchas in using it to render gifs on the web with canvas and support most gif files. I thought this example might be useful for people trying to use omggif in a web context.

mnutt avatar Jan 05 '19 03:01 mnutt

(it's pretty much just the player extracted from https://movableink.github.io/gif-inspector/)

mnutt avatar Jan 05 '19 03:01 mnutt

Sorry for the delay, did you close it because it sat for too long or another reason? Thanks!

deanm avatar Apr 10 '19 08:04 deanm

@deanm thanks for the review, there were definitely some edge cases that this wasn't catching. I think I've addressed them all now.

mnutt avatar Jul 08 '19 15:07 mnutt

@deanm ping Is there anything blocking the progress of the pull request?

mathieucaroff avatar Mar 15 '20 00:03 mathieucaroff

https://stackoverflow.com/questions/60691364/extract-frames-from-gif-using-a-light-browser-js-libary-like-omggif

import { GifReader } from 'omggif';

export const loadGifFrameList = async (
    gifUrl: string,
): Promise<ImageData[]> => {
    const response = await fetch(gifUrl);
    const blob = await response.blob();
    const arrayBuffer = await blob.arrayBuffer();
    const intArray = new Uint8Array(arrayBuffer);

    const reader = new GifReader(intArray as Buffer);

    const info = reader.frameInfo(0);

    return new Array(reader.numFrames()).fill(0).map((_, k) => {
        const image = new ImageData(info.width, info.height);

        reader.decodeAndBlitFrameRGBA(k, image.data as any);

        return image;
    });
};

mathieucaroff avatar Mar 16 '20 18:03 mathieucaroff