Skip to content

Instantly share code, notes, and snippets.

@jhuckaby
Created January 24, 2019 05:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhuckaby/0faa68f013bc199666d3dbcedf9c82ec to your computer and use it in GitHub Desktop.
Save jhuckaby/0faa68f013bc199666d3dbcedf9c82ec to your computer and use it in GitHub Desktop.
Preload all Advent Pro styles, then render regular style using node-canvas
const { registerFont, createCanvas } = require('canvas');
registerFont( 'AdventPro-Bold.ttf', { family: "AdventProBold" } );
registerFont( 'AdventPro-ExtraLight.ttf', { family: "AdventProExtraLight" } );
registerFont( 'AdventPro-Light.ttf', { family: "AdventProLight" } );
registerFont( 'AdventPro-Medium.ttf', { family: "AdventProMedium" } );
registerFont( 'AdventPro-Regular.ttf', { family: "AdventProRegular" } );
registerFont( 'AdventPro-SemiBold.ttf', { family: "AdventProSemiBold" } );
registerFont( 'AdventPro-Thin.ttf', { family: "AdventProThin" } );
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