Skip to content

Instantly share code, notes, and snippets.

@jhuckaby
Created January 24, 2019 05:07
Show Gist options
  • Save jhuckaby/a096d24343f48bef6b867e081c6b9868 to your computer and use it in GitHub Desktop.
Save jhuckaby/a096d24343f48bef6b867e081c6b9868 to your computer and use it in GitHub Desktop.
Preload single regular Advent Pro style, then render it using node-canvas
const { registerFont, createCanvas } = require('canvas');
registerFont( 'AdventPro-Regular.ttf', { family: "AdventProRegular" } );
var canvas = createCanvas( 600, 100 );
var ctx = canvas.getContext( '2d' );
ctx.fillStyle = '#ffffff';
ctx.fillRect( 0, 0, canvas.width, canvas.height );
ctx.font = "normal normal 30px AdventProRegular";
ctx.fillStyle = '#000000';
ctx.fillText( "Now is the time for all good men.", 10, 50 );
require('fs').writeFileSync( "out.png", canvas.toBuffer('image/png') );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment