Skip to content

Commit

Permalink
add Canvas#{png,jpeg}Stream() alias of create* legacy methods
Browse files Browse the repository at this point in the history
create* is annoying
  • Loading branch information
tj committed Oct 26, 2012
1 parent 64af9b2 commit 0d39dae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
10 changes: 5 additions & 5 deletions Readme.md
Expand Up @@ -79,14 +79,14 @@ img.dataMode = Image.MODE_MIME | Image.MODE_IMAGE; // Both are tracked

If image data is not tracked, and the Image is drawn to an image rather than a PDF canvas, the output will be junk. Enabling mime data tracking has no benefits (only a slow down) unless you are generating a PDF.

### Canvas#createPNGStream()
### Canvas#pngStream()

To create a `PNGStream` simply call `canvas.createPNGStream()`, and the stream will start to emit _data_ events, finally emitting _end_ when finished. If an exception occurs the _error_ event is emitted.
To create a `PNGStream` simply call `canvas.pngStream()`, and the stream will start to emit _data_ events, finally emitting _end_ when finished. If an exception occurs the _error_ event is emitted.

```javascript
var fs = require('fs')
, out = fs.createWriteStream(__dirname + '/text.png')
, stream = canvas.createPNGStream();
, stream = canvas.pngStream();

stream.on('data', function(chunk){
out.write(chunk);
Expand All @@ -99,9 +99,9 @@ stream.on('end', function(){

Currently _only_ sync streaming is supported, however we plan on supporting async streaming as well (of course :) ). Until then the `Canvas#toBuffer(callback)` alternative is async utilizing `eio_custom()`.

### Canvas#createJPEGStream()
### Canvas#jpegStream()

You can likewise create a `JPEGStream` by calling `canvas.createJPEGStream()` with some optional parameters; functionality is otherwise identical to `createPNGStream()`. See `examples/crop.js` for an example.
You can likewise create a `JPEGStream` by calling `canvas.jpegStream()` with some optional parameters; functionality is otherwise identical to `pngStream()`. See `examples/crop.js` for an example.

### Canvas#toBuffer()

Expand Down
4 changes: 4 additions & 0 deletions lib/canvas.js
Expand Up @@ -116,6 +116,7 @@ Canvas.prototype.getContext = function(contextId){
* @api public
*/

Canvas.prototype.pngStream =
Canvas.prototype.createPNGStream = function(){
return new PNGStream(this);
};
Expand All @@ -127,6 +128,7 @@ Canvas.prototype.createPNGStream = function(){
* @api public
*/

Canvas.prototype.syncPNGStream =
Canvas.prototype.createSyncPNGStream = function(){
return new PNGStream(this, true);
};
Expand All @@ -139,6 +141,7 @@ Canvas.prototype.createSyncPNGStream = function(){
* @api public
*/

Canvas.prototype.jpegStream =
Canvas.prototype.createJPEGStream = function(options){
return this.createSyncJPEGStream(options);
};
Expand All @@ -151,6 +154,7 @@ Canvas.prototype.createJPEGStream = function(options){
* @api public
*/

Canvas.prototype.syncJPEGStream =
Canvas.prototype.createSyncJPEGStream = function(options){
options = options || {};
return new JPEGStream(this, {
Expand Down

0 comments on commit 0d39dae

Please sign in to comment.