omggif
omggif copied to clipboard
example browser script
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.
(it's pretty much just the player extracted from https://movableink.github.io/gif-inspector/)
Sorry for the delay, did you close it because it sat for too long or another reason? Thanks!
@deanm thanks for the review, there were definitely some edge cases that this wasn't catching. I think I've addressed them all now.
@deanm ping Is there anything blocking the progress of the pull request?
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;
});
};