Created
November 5, 2010 19:07
-
-
Save rauchg/664622 to your computer and use it in GitHub Desktop.
How to install
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
port install cairo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Module dependencies. | |
*/ | |
var Canvas = require('canvas') | |
, canvas = new Canvas(150, 150) | |
, ctx = canvas.getContext('2d') | |
, fs = require('fs'); | |
ctx.fillRect(0,0,150,150); // Draw a rectangle with default settings | |
ctx.save(); // Save the default state | |
ctx.fillStyle = '#09F' // Make changes to the settings | |
ctx.fillRect(15,15,120,120); // Draw a rectangle with new settings | |
ctx.save(); // Save the current state | |
ctx.fillStyle = '#FFF' // Make changes to the settings | |
ctx.globalAlpha = 0.5; | |
ctx.fillRect(30,30,90,90); // Draw a rectangle with new settings | |
ctx.restore(); // Restore previous state | |
ctx.fillRect(45,45,60,60); // Draw a rectangle with restored settings | |
ctx.restore(); // Restore original state | |
ctx.fillRect(60,60,30,30); // Draw a rectangle with restored settings | |
var out = fs.createWriteStream(__dirname + '/state.png') | |
, stream = canvas.createPNGStream(); | |
stream.on('data', function(chunk){ | |
out.write(chunk); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install canvas |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment