Skip to content

Instantly share code, notes, and snippets.

@Jimbly
Created March 27, 2019 20:25
Show Gist options
  • Save Jimbly/ea88b0e96817a30ad8a5c230a3776590 to your computer and use it in GitHub Desktop.
Save Jimbly/ea88b0e96817a30ad8a5c230a3776590 to your computer and use it in GitHub Desktop.
Testing gifwrap
const fs = require('fs');
const { GifCodec, BitmapImage } = require('./');
const Jimp = require('jimp');
let gif = fs.readFileSync('test/fixtures/rnaples-offsets-public.gif');
const codec = new GifCodec();
codec.decodeGif(gif).then((sourceGif) => {
const w = sourceGif.width;
const h = sourceGif.height;
const num_frames = sourceGif.frames.length;
let composite_jimp = new Jimp(w * num_frames, h, 0xFF00FFff);
const composite_bitmap = new BitmapImage(1, 1, 0);
composite_bitmap.bitmap = composite_jimp.bitmap;
const frame_jimp = new Jimp(1, 1, 0);
sourceGif.frames.forEach((frame, idx) => {
frame_jimp.bitmap = frame.bitmap;
if (idx !== 0) {
// composite_jimp.blit(composite_jimp, idx * w, 0, (idx - 1) * w, 0, w, h);
composite_bitmap.blit(composite_bitmap, idx * w, 0, (idx - 1) * w, 0, w, h); // faster
}
composite_jimp.composite(frame_jimp, idx * w + frame.xOffset, frame.yOffset);
});
composite_jimp.getBuffer('image/png', function (err, data) {
if (err) {
throw err;
}
fs.writeFileSync('out.png', data);
});
});
@Jimbly
Copy link
Author

Jimbly commented Mar 27, 2019

Expected results:
out_good_128

Actual results:
out_bad_128

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment