Skip to content

Instantly share code, notes, and snippets.

@eugeneware
Created November 3, 2016 21:56
Show Gist options
  • Save eugeneware/166e844b5b294b5b38daed562d398a5c to your computer and use it in GitHub Desktop.
Save eugeneware/166e844b5b294b5b38daed562d398a5c to your computer and use it in GitHub Desktop.
canvas test
var Canvas = require('canvas')
, Image = Canvas.Image
, canvas = new Canvas(200, 200)
, ctx = canvas.getContext('2d');
ctx.fillStyle = '#f00';
ctx.fillRect(0, 0, 200, 200);
ctx.strokeStyle = '#000';
ctx.fillStyle = '#000';
ctx.strokeStyle = 'rgba(0,0,0,0.5)';
ctx.font = '30px Helvetical';
ctx.rotate(.1);
ctx.strokeText("Awesome!", 50, 100);
ctx.fillText("Awesome!", 50, 100);
var te = ctx.measureText('Awesome!');
ctx.strokeStyle = 'rgba(0,0,0,0.5)';
ctx.beginPath();
ctx.lineTo(50, 102);
ctx.lineTo(50 + te.width, 102);
ctx.stroke();
var fs = require('fs');
canvas.pngStream().pipe(fs.createWriteStream('./out.png'));
console.log('<img src="' + canvas.toDataURL() + '" />');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment