Skip to content

Instantly share code, notes, and snippets.

@RameshRM
Created February 11, 2016 05:30
Show Gist options
  • Save RameshRM/bbf9c287a3be169e92de to your computer and use it in GitHub Desktop.
Save RameshRM/bbf9c287a3be169e92de to your computer and use it in GitHub Desktop.
var fs = require('fs');
var Canvas = require('canvas')
, Image = Canvas.Image
, canvas = new Canvas(400, 600)
, ctx = canvas.getContext('2d');
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();
// console.log('<img src="' + canvas.toDataURL() + '" />');
var squid = fs.readFileSync('./squid.png');
ctx.beginPath();
ctx.font = '30px Impact';
ctx.fillText("Awesome!", 100, 70);
ctx.font = '30px Impact';
ctx.fillText("Awesome Text!", 100, 400);
img = new Image;
img.src = squid;
ctx.drawImage(img, 10, 100, img.width, img.height );
var fs = require('fs')
, out = fs.createWriteStream(__dirname + '/text.png')
, stream = canvas.pngStream();
stream.on('data', function(chunk){
out.write(chunk);
});
stream.on('end', function(){
console.log('saved png');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment