gifencoder
Advanced tools
Comparing version 0.2.0 to 1.0.0
@@ -16,3 +16,2 @@ /* | ||
function ByteArray() { | ||
this.cursor = 0; | ||
this.data = []; | ||
@@ -116,8 +115,8 @@ } | ||
if (this.readStreams.length === 0) return; | ||
if (this.out.cursor < this.out.data.length) { | ||
if (this.out.data.length) { | ||
this.readStreams.forEach(function (rs) { | ||
rs.push(new Buffer(self.out.data.slice(self.out.cursor, self.out.data.length))); | ||
rs.push(new Buffer(self.out.data)); | ||
}); | ||
this.out.data = []; | ||
} | ||
this.out.cursor = this.out.data.length; | ||
}; | ||
@@ -453,9 +452,2 @@ | ||
/* | ||
Retrieves the GIF stream | ||
*/ | ||
GIFEncoder.prototype.stream = function() { | ||
return this.out; | ||
}; | ||
module.exports = GIFEncoder; |
{ | ||
"name": "gifencoder", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "Streaming server-side animated (and non-animated) gif generation for node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -21,48 +21,20 @@ # gifencoder | ||
## Example Usage | ||
## Streaming API - Duplex Piping with Writes | ||
You can also stream writes of pixel data (or canvas contexts) to the encoder: | ||
``` js | ||
var GIFEncoder = require('gifencoder'); | ||
var Canvas = require('canvas'); | ||
var fs = require('fs'); | ||
var encoder = new GIFEncoder(320, 240); | ||
encoder.start(); | ||
encoder.setRepeat(0); // 0 for repeat, -1 for no-repeat | ||
encoder.setDelay(500); // frame delay in ms | ||
encoder.setQuality(10); // image quality. 10 is default. | ||
// use node-canvas | ||
var canvas = new Canvas(320, 240); | ||
var ctx = canvas.getContext('2d'); | ||
// red rectangle | ||
ctx.fillStyle = '#ff0000'; | ||
ctx.fillRect(0, 0, 320, 240); | ||
encoder.addFrame(ctx); | ||
// green rectangle | ||
ctx.fillStyle = '#00ff00'; | ||
ctx.fillRect(0, 0, 320, 240); | ||
encoder.addFrame(ctx); | ||
// blue rectangle | ||
ctx.fillStyle = '#0000ff'; | ||
ctx.fillRect(0, 0, 320, 240); | ||
encoder.addFrame(ctx); | ||
encoder.finish(); | ||
var buf = encoder.stream().getData(); | ||
fs.writeFile('myanimated.gif', buf, function (err) { | ||
// animated GIF written to myanimated.gif | ||
}); | ||
var encoder = new GIFEncoder(854, 480); | ||
var bitMapStream = makeMyBitMaps(); // read stream that creates RGBA 1-dimensional bitmaps | ||
bitMapStream | ||
.pipe(encoder.createWriteStream({ repeat: -1, delay: 500, quality: 10 })) | ||
.pipe(fs.createWriteStream('myanimated.gif')); | ||
``` | ||
The above code will render an image like: | ||
NB: The chunks that get emitted by your read stream must either by a 1-dimensional bitmap of RGBA | ||
data (either an array or Buffer), or a canvas 2D `context`. | ||
![Animated GIF](https://raw.github.com/eugeneware/gifencoder/master/examples/myanimated.gif) | ||
## Example: Streaming API - Reads | ||
## Streaming API - Reads | ||
You can also use a streaming API to receive data: | ||
@@ -106,16 +78,2 @@ | ||
## Streaming API - Writes | ||
You can also stream writes of pixel data (or canvas contexts) to the encoder: | ||
``` js | ||
var GIFEncoder = require('gifencoder'); | ||
var encoder = new GIFEncoder(854, 480); | ||
var bitMapStream = makeMyBitMaps(); // read stream that creates RGBA 1-dimensional bitmaps | ||
bitMapStream | ||
.pipe(encoder.createWriteStream({ repeat: -1, delay: 500, quality: 10 })) | ||
.pipe(fs.createWriteStream('myanimated.gif')); | ||
``` | ||
NB: The chunks that get emitted by your read stream must either by a 1-dimensional bitmap of RGBA | ||
data (either an array or Buffer), or a canvas 2D `context`. | ||
![Animated GIF](https://raw.github.com/eugeneware/gifencoder/master/examples/myanimated.gif) |
@@ -25,36 +25,2 @@ var expect = require('expect.js'), | ||
describe('GIFEncoder', function() { | ||
it('should be able to Generate a PNG', function(done) { | ||
var buf = fs.readFileSync(fixtures('in.png')); | ||
var img = new Canvas.Image(); | ||
img.src = buf; | ||
var canvas = new Canvas(img.width, img.height); | ||
var ctx = canvas.getContext('2d'); | ||
var encoder = new GIFEncoder(img.width, img.height); | ||
encoder.start(); | ||
encoder.setRepeat(-1); | ||
encoder.setDelay(500); | ||
encoder.setQuality(10); | ||
ctx.drawImage(img, 0, 0); | ||
encoder.addFrame(ctx); | ||
ctx.fillStyle = '#ff0000'; | ||
ctx.fillRect(0, 0, img.width, img.height); | ||
encoder.addFrame(ctx); | ||
ctx.fillStyle = '#0000ff'; | ||
ctx.fillRect(0, 0, img.width, img.height); | ||
encoder.addFrame(ctx); | ||
encoder.finish(); | ||
var out = encoder.stream().getData(); | ||
var expected = fs.readFileSync(fixtures('out.gif')); | ||
expect(out).to.eql(expected); | ||
done(); | ||
}); | ||
it('should expose a read streaming interface', function(done) { | ||
@@ -61,0 +27,0 @@ var buf = fs.readFileSync(fixtures('in.png')); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
1
136998
1606
78