twolfson / gif-encoder

Streaming GIF encoder
The Unlicense
86 stars 10 forks source link

Weird gif #22

Closed 19hours closed 2 years ago

19hours commented 2 years ago

Thanks for building this lib, I am facing some problems generating a gif. Is it my data that is corrupted?

sharp(jpeg)
      .raw()
      .toBuffer({ resolveWithObject: true })
      .then((value) => {
        const pixels = new Uint8ClampedArray(value.data.buffer);
        console.log(pixels);
        var gif = new GifEncoder(600, 900);
        var file = require("fs").createWriteStream("img.gif");
        gif.pipe(file);
        gif.writeHeader();
        gif.addFrame(pixels);
        gif.finish();
      });

The end result is this 1 frame gif:

Screenshot 2022-08-06 at 11 34 50 AM
19hours commented 2 years ago

When I check the jpeg file it is a valid jpeg image

twolfson commented 2 years ago

The code looks reasonable to me. I have a few things I'd sanity check on:

Hope that helps =)

19hours commented 2 years ago

Dimensions was the problem, thanks ~