Created
November 3, 2016 21:56
-
-
Save eugeneware/166e844b5b294b5b38daed562d398a5c to your computer and use it in GitHub Desktop.
canvas test
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
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