paper.js/examples/Node.js/RemoteRaster.js
Jürg Lehni e232ebc443 Examples: Move away from using a symlink to be able to require('paper') from within examples.
- Node 5 / NPM 3 struggles with it
- It never worked on Windows
2016-01-31 12:43:38 +01:00

28 lines
793 B
JavaScript

// Please note: When loading paper as a normal module installed in node_modules,
// you would use this instead:
// var paper = require('paper');
var paper = require('../../dist/paper-full.js');
var fs = require('fs');
var canvas = paper.createCanvas(800, 600);
paper.setup(canvas);
var url = 'http://assets.paperjs.org/images/marilyn.jpg';
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');
stream = canvas.createPNGStream();
stream.on('data', function(chunk) {
out.write(chunk);
});
stream.on('end', function() {
console.log('saved png');
});
};