1.0.1 • Published 9 months ago
canvas-fonts-rubik v1.0.1
canvas-fonts-rubik
This is a Rubik font package for canvas.
Installation
npm i canvas-fonts-rubik
Usage
import { createCanvas, registerFont } from 'canvas';
registerFont(require("canvas-fonts-rubik"), { family: 'Rubik' });
const canvas = createCanvas(400, 48);
const ctx = canvas.getContext('2d');
ctx.font = `24px "Arial"`;
ctx.fillText("Arial", 5, 30);
const png = canvas.toBuffer();
Creating your own Fonts
To use your own fonts, simply:
- Create a new npm package
- Add your font file to the same directory as the
package.json
created in step 1. - Add the following
index.js
file in that same directory:
// Replace "MyAwesomeFont.ttf" with the filename of your font!
module.exports = require('path').join(__dirname, "MyAwesomeFont.ttf")
- Publish to npm!