Skip to content

Instantly share code, notes, and snippets.

@bteitelb
Created December 2, 2011 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bteitelb/1423054 to your computer and use it in GitHub Desktop.
Save bteitelb/1423054 to your computer and use it in GitHub Desktop.
node-canvas shadowBlur test
// Step 1:
// Retrieve test image:
// wget http://s3.amazonaws.com/tastrix/440/large_orig/shiso_trans.png
//
// Step 2:
// Then, run this through node.js
//
// Step 3:
// Inspect shade_test.png; the overlayed squares have drop shadow with Gaussian blur, the circle of leaves does not
var Canvas = require('canvas')
, Image = Canvas.Image
, canvas = new Canvas(2000, 2000)
, ctx = canvas.getContext('2d')
, fs = require('fs');
var carrots = fs.readFileSync(__dirname + '/shiso_trans.png');
img = new Image;
img.src = carrots;
ctx.fillStyle = '#FFF';
ctx.fillRect(0,0,1000,1000);
ctx.shadowColor = "#000";
ctx.shadowOffsetX = 3;
ctx.shadowOffsetY = 3;
ctx.shadowBlur = 15;
ctx.translate(300, 300);
ctx.save();
for (var i = 0; i < 8; i++) {
ctx.drawImage(img, 0, 0, 200, 300);
ctx.rotate(Math.PI / 4);
}
ctx.restore();
for (var i = 0; i < 3; i++) {
ctx.fillStyle = ['#F00', '#0F0', '#00F'][i];
ctx.translate(30, 30);
ctx.fillRect(300,300,310,310);
}
var out = fs.createWriteStream(__dirname + '/shade_test.png')
, stream = canvas.createPNGStream();
stream.on('data', function(chunk){
out.write(chunk);
});
@indus
Copy link

indus commented May 13, 2014

if you still need a solution for this try out ncc (https://github.com/indus/ncc)
ncc (node-chrome-canvas) uses the original HTML5 CanvasElement from Chrome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment