Created
March 27, 2019 20:25
-
-
Save Jimbly/ea88b0e96817a30ad8a5c230a3776590 to your computer and use it in GitHub Desktop.
Testing gifwrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Expected results:
![out_good_128](https://user-images.githubusercontent.com/774383/55110044-6c11d280-5094-11e9-8371-6006526bce8a.png)
Actual results:
![out_bad_128](https://user-images.githubusercontent.com/774383/55110054-6d42ff80-5094-11e9-8cc6-e7e52b83c179.png)