2013-12-03 17:07:54 -05:00
|
|
|
var paper = require('paper');
|
|
|
|
var fs = require('fs');
|
|
|
|
|
2016-01-26 05:41:49 -05:00
|
|
|
var canvas = paper.createCanvas(800, 600);
|
2013-12-03 17:07:54 -05:00
|
|
|
paper.setup(canvas);
|
|
|
|
|
2015-05-31 04:50:04 -04:00
|
|
|
var url = 'http://assets.paperjs.org/images/marilyn.jpg';
|
2013-12-03 17:07:54 -05:00
|
|
|
var raster = new paper.Raster(url);
|
|
|
|
raster.position = paper.view.center;
|
|
|
|
|
|
|
|
raster.onLoad = function() {
|
|
|
|
console.log('The image has loaded:' + raster.bounds);
|
|
|
|
|
|
|
|
// Saving the canvas to a file.
|
|
|
|
out = fs.createWriteStream(__dirname + '/canvas.png');
|
2016-01-26 05:41:49 -05:00
|
|
|
stream = canvas.createPNGStream();
|
2013-12-03 17:07:54 -05:00
|
|
|
|
2013-12-16 15:40:40 -05:00
|
|
|
stream.on('data', function(chunk) {
|
2013-12-03 17:07:54 -05:00
|
|
|
out.write(chunk);
|
|
|
|
});
|
|
|
|
|
|
|
|
stream.on('end', function() {
|
|
|
|
console.log('saved png');
|
|
|
|
});
|
|
|
|
};
|