Browse Source

add Canvas#{png,jpeg}Stream() alias of create* legacy methods

create* is annoying
v1.x
TJ Holowaychuk 12 years ago
parent
commit
0d39dae66c
  1. 10
      Readme.md
  2. 4
      lib/canvas.js

10
Readme.md

@ -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. 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 ```javascript
var fs = require('fs') var fs = require('fs')
, out = fs.createWriteStream(__dirname + '/text.png') , out = fs.createWriteStream(__dirname + '/text.png')
, stream = canvas.createPNGStream(); , stream = canvas.pngStream();
stream.on('data', function(chunk){ stream.on('data', function(chunk){
out.write(chunk); out.write(chunk);
@ -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()`. 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() ### Canvas#toBuffer()

4
lib/canvas.js

@ -116,6 +116,7 @@ Canvas.prototype.getContext = function(contextId){
* @api public * @api public
*/ */
Canvas.prototype.pngStream =
Canvas.prototype.createPNGStream = function(){ Canvas.prototype.createPNGStream = function(){
return new PNGStream(this); return new PNGStream(this);
}; };
@ -127,6 +128,7 @@ Canvas.prototype.createPNGStream = function(){
* @api public * @api public
*/ */
Canvas.prototype.syncPNGStream =
Canvas.prototype.createSyncPNGStream = function(){ Canvas.prototype.createSyncPNGStream = function(){
return new PNGStream(this, true); return new PNGStream(this, true);
}; };
@ -139,6 +141,7 @@ Canvas.prototype.createSyncPNGStream = function(){
* @api public * @api public
*/ */
Canvas.prototype.jpegStream =
Canvas.prototype.createJPEGStream = function(options){ Canvas.prototype.createJPEGStream = function(options){
return this.createSyncJPEGStream(options); return this.createSyncJPEGStream(options);
}; };
@ -151,6 +154,7 @@ Canvas.prototype.createJPEGStream = function(options){
* @api public * @api public
*/ */
Canvas.prototype.syncJPEGStream =
Canvas.prototype.createSyncJPEGStream = function(options){ Canvas.prototype.createSyncJPEGStream = function(options){
options = options || {}; options = options || {};
return new JPEGStream(this, { return new JPEGStream(this, {

Loading…
Cancel
Save