Created
January 24, 2019 05:06
-
-
Save jhuckaby/0faa68f013bc199666d3dbcedf9c82ec to your computer and use it in GitHub Desktop.
Preload all Advent Pro styles, then render regular style using node-canvas
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
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