Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { registerFont, createCanvas } = require("canvas");
const { registerFont, createCanvas, deregisterAllFonts } = require("canvas");

/**
* Convert text to PNG image.
Expand Down Expand Up @@ -30,10 +30,11 @@ const { registerFont, createCanvas } = require("canvas");
const text2png = (text, options = {}) => {
// Options
options = parseOptions(options);

var isFontLoadedInMemory = false
// Register a custom font
if (options.localFontPath && options.localFontName) {
registerFont(options.localFontPath, { family: options.localFontName });
isFontLoadedInMemory = true;
}

const canvas = createCanvas(0, 0);
Expand Down Expand Up @@ -158,7 +159,9 @@ const text2png = (text, options = {}) => {

offsetY += lineHeight;
});

if(isFontLoadedInMemory){
deregisterAllFonts()
}
switch (options.output) {
case "buffer":
return canvas.toBuffer();
Expand Down