import * as gw from "gif-writer" ; import * as fs from "fs" ; var indexedColorImage = new gw . IndexedColorImage ( { width : 9 , height : 9 } , [ 0 , 0 , 0 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , 1 , 0 , 0 , 0 , ] , [ 0 , 0 , 0 , 255 , 255 , 255 ] ) ; class MyOutputStream implements gw . IOutputStream { buffer : number [ ] = [ ] ; writeByte ( b ) { this . buffer . push ( b ) ; } writeBytes ( bb ) { Array . prototype . push . apply ( this . buffer , bb ) ; } } var outputStream = new MyOutputStream ( ) ; var gifWriter = new gw . GifWriter ( outputStream ) ; gifWriter . writeHeader ( ) ; gifWriter . writeLogicalScreenInfo ( { width : indexedColorImage . width , height : indexedColorImage . height } ) ; gifWriter . writeTableBasedImage ( indexedColorImage ) ; gifWriter . writeTrailer ( ) ; var buf = new Buffer ( outputStream . buffer ) ; fs . writeFile ( 'test.gif' , buf , ( err ) => { if ( err ) console . log ( err ) ; else console . log ( 'It\'s saved!' ) ; } ) ;