sharp icon indicating copy to clipboard operation
sharp copied to clipboard

Cannot use custom fonts "Fontconfig error: Cannot load default config file: No such file: (null)"

Open MarianoFacundoArch opened this issue 1 year ago • 1 comments

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");

MarianoFacundoArch avatar Apr 19 '24 15:04 MarianoFacundoArch

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.

lovell avatar Apr 19 '24 16:04 lovell

I hope this information helped. Please feel free to re-open with more details if further assistance is required.

lovell avatar May 16 '24 12:05 lovell

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 avatar Jul 15 '24 12:07 JurajKavka

@JurajKavka Please see https://github.com/lovell/sharp/issues/2399#issuecomment-2324484840

lovell avatar Sep 03 '24 09:09 lovell