2016-01-29 17:06:31 -05:00
|
|
|
// Please note: When loading paper as a normal module installed in node_modules,
|
|
|
|
// you would use this instead:
|
2017-04-19 14:32:12 -04:00
|
|
|
// var paper = require('paper-jsdom-canvas');
|
2016-02-15 17:59:31 -05:00
|
|
|
var paper = require('../../dist/paper-core.js');
|
2013-12-03 17:07:54 -05:00
|
|
|
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() {
|
2016-02-15 17:59:31 -05:00
|
|
|
paper.view.update();
|
2013-12-03 17:07:54 -05:00
|
|
|
console.log('The image has loaded:' + raster.bounds);
|
|
|
|
|
|
|
|
// Saving the canvas to a file.
|
|
|
|
out = fs.createWriteStream(__dirname + '/canvas.png');
|
2017-10-04 16:39:19 -04:00
|
|
|
stream = canvas.pngStream();
|
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');
|
|
|
|
});
|
|
|
|
};
|
2016-04-05 02:26:43 -04:00
|
|
|
|
|
|
|
raster.onError = function(message) {
|
|
|
|
console.error(message);
|
|
|
|
};
|