Cannot use custom fonts "Fontconfig error: Cannot load default config file: No such file: (null)"
I am providing a valid value for fontfile and even the font name, but just doesn't work. I get Fontconfig error: Cannot load default config file: No such file: (null).
File exists, is checked, and even I am providing the font name (I tried not setting the font variable at all and it is the same)
const desiredFontFile = path.join(
__dirname,
`../../../assets/fonts/SuperFunky.ttf`
);
console.log(desiredFontFile);
if (!checkFileExists(desiredFontFile)) {
throw new Error("Error retrieving font file");
}
await sharp({
text: {
text: "TEST",
fontfile: desiredFontFile,
font: "Super Funky",
rgba: true,
dpi: 3000,
},
}).toFile("test.png");
https://sharp.pixelplumbing.com/install#fonts
If fontconfig configuration is not found, the following error will occur:
Fontconfig error: Cannot load default config file
You'll need to ensure fontconfig can be found.
The section in the issue template that asked you to provide useful information about your OS etc. was ignored/deleted.
I hope this information helped. Please feel free to re-open with more details if further assistance is required.
Hello,
following documentation about fonts installation, it is still not working for me on MacOS.
My MacOS is Sonoma, version 14.5. I installed fonconfig with brew and it is installed in /opt/homebrew/Cellar/fontconfig/2.15.0/. So I tried setting up env variables and run my NodeJS project
$ PANGOCAIRO_BACKEND=fontconfig FONTCONFIG_PATH=/opt/homebrew/Cellar/fontconfig/2.15.0 npm start
but when I tey compose text over image, I'm getting error
(process:19240): Pango-CRITICAL **: 14:10:11.743: Unknown $PANGOCAIRO_BACKEND value.
Available backends are: coretext
(process:19240): Pango-CRITICAL **: 14:10:11.744: pango_font_map_create_context: assertion 'fontmap != NULL' failed
Fontconfig error: Cannot load default config file: No such file: (null)
(process:19240): Pango-CRITICAL **: 14:10:11.746: pango_cairo_font_map_set_resolution: assertion 'PANGO_IS_CAIRO_FONT_MAP (fontmap)' failed
(process:19240): Pango-CRITICAL **: 14:10:11.746: pango_layout_new: assertion 'context != NULL' failed
(process:19240): Pango-CRITICAL **: 14:10:11.746: pango_layout_set_markup_with_accel: assertion 'PANGO_IS_LAYOUT (layout)' failed
(process:19240): Pango-CRITICAL **: 14:10:11.746: pango_layout_set_font_description: assertion 'layout != NULL' failed
(process:19240): Pango-CRITICAL **: 14:10:11.746: pango_layout_set_justify: assertion 'layout != NULL' failed
(process:19240): Pango-CRITICAL **: 14:10:11.746: pango_layout_set_spacing: assertion 'layout != NULL' failed
(process:19240): Pango-CRITICAL **: 14:10:11.746: pango_layout_set_alignment: assertion 'layout != NULL' failed
(process:19240): Pango-CRITICAL **: 14:10:11.746: pango_layout_set_wrap: assertion 'PANGO_IS_LAYOUT (layout)' failed
(process:19240): Pango-CRITICAL **: 14:10:11.746: pango_layout_set_width: assertion 'layout != NULL' failed
Please clould you help me with that issue?
Thank You.
@JurajKavka Please see https://github.com/lovell/sharp/issues/2399#issuecomment-2324484840