jimp-dev / gifwrap

A Jimp-compatible library for working with GIFs
MIT License
71 stars 17 forks source link

Encoding previously decoded gif results in different looking gif #17

Closed ArtBIT closed 5 years ago

ArtBIT commented 5 years ago

Here's a minimal example that illustrates this issue. It loads a gif image, decodes it and then immediately encodes it as a new image, which ends up looking completely different from the input image:

var fs = require("fs");
var path = require("path");
var GifCodec = require("gifwrap").GifCodec;

fs.readFile(path.join(__dirname, "./input.gif"), (err, buffer) => {
  if (err) throw err;
  var codec = new GifCodec();
  codec.decodeGif(buffer).then(gif => {
    codec
      .encodeGif(gif.frames, {
        loops: gif.loops,
        colorScope: gif.colorScope
      })
      .then(gif => {
        fs.writeFileSync(path.join(__dirname, "./output.gif"), gif.buffer);
      });
  });
});

input.gif

input.gif

output.gif

output.gif

I have noticed similar behaviour with gifs that have frames with x and/or y offsets.

jtlapp commented 5 years ago

I just tested this with the latest version of gifwrap. If it wasn't working before, it is working now. Perhaps #18 fixed it. Thanks for reporting the problem. Let me know if it still persists.

ArtBIT commented 5 years ago

It works for me as well with v0.9.2

jtlapp commented 5 years ago

Excellent! Thanks for checking.