@ -45,25 +45,30 @@ If not previously installed, you will want to install the [cairo graphics librar
node-canvas adds `Image#src=Buffer` support, allowing you to read images from disc, redis, etc and apply them via `ctx.drawImage()`. Below we draw scaled down squid png by reading it from the disk with node's I/O.
Below is an example of a canvas drawing it-self as the source several time:
```javascript
var img = new Image;
img.src = canvas.toBuffer();
ctx.drawImage(img, 0, 0, 50, 50);
ctx.drawImage(img, 50, 0, 50, 50);
ctx.drawImage(img, 100, 0, 50, 50);
```
### Canvas#createPNGStream()
To create a `PNGStream` simple 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.
```javascript
var fs = require('fs')
, out = fs.createWriteStream(__dirname + '/text.png')
, stream = canvas.createPNGStream();
@ -75,6 +80,7 @@ If not previously installed, you will want to install the [cairo graphics librar
stream.on('end', function(){
console.log('saved png');
});
```
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()`.
@ -82,31 +88,36 @@ Currently _only_ sync streaming is supported, however we plan on supporting asyn
A call to `Canvas#toBuffer()` will return a node `Buffer` instance containing all of the PNG data.
```javascript
canvas.toBuffer();
```
### Canvas#toBuffer() async
Optionally we may pass a callback function to `Canvas#toBuffer()`, and this process will be performed asynchronously, and will `callback(err, buf)`.
```javascript
canvas.toBuffer(function(err, buf){
});
```
### Canvas#toDataURL() async
Optionally we may pass a callback function to `Canvas#toDataURL()`, and this process will be performed asynchronously, and will `callback(err, str)`.
```javascript
canvas.toDataURL(function(err, str){
});
or specify the mime type:
```javascript
canvas.toDataURL('image/png', function(err, str){
});
```
### CanvasRenderingContext2d#patternQuality
@ -141,7 +152,9 @@ Given one of the values below will alter pattern (gradients, images, etc) render