react-gif-player icon indicating copy to clipboard operation
react-gif-player copied to clipboard

Grab first frame more quickly with GIF stream

Open benwiley4000 opened this issue 6 years ago • 3 comments

It might be possible to automatically turn the first GIF frame into a data url with the help of gif-stream and pixel-stream - we could write the image data after the first frame has loaded to a canvas element, maybe with save-pixels, and extract the data url.

benwiley4000 avatar Jul 30 '17 02:07 benwiley4000

Should be possible to use this method to get first frame from gif - https://stackoverflow.com/a/4276742/3772379

olessavluk avatar May 08 '19 18:05 olessavluk

I already have a module I wrote for getting the first frame from a GIF: https://github.com/benwiley4000/gif-frames

The problem is that get-pixels doesn't fire its callback until the whole image is loaded. I wanted to stream the first frame then cut off the rest of the stream.

Looking at this again I think it's possible with this web-streams-node module which could let me convert that gif-stream into a WHATWG web stream, so I can pipe the fetch() body stream into it. I might try it out!

benwiley4000 avatar May 08 '19 18:05 benwiley4000

I've got a proof-of-concept working here: https://codesandbox.io/embed/n15vp7r7wm

Need to figure out the best way to add that to the library... preferably not adding on too many kilobytes. It might be best to make it an optional add-on module.

benwiley4000 avatar May 10 '19 03:05 benwiley4000