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 2 months 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