Skip to content

Cannot load fonts in Web Worker #1286

@av01d

Description

@av01d

I am confused... was issue #289 ever considered? Using fonts in a WebWorker (still) does not work.
Example worker:

importScripts('./jimp.js');

(async () => {

  const font = await Jimp.loadFont('fonts/open-sans/open-sans-32-black/open-sans-32-black.fnt');

  self.addEventListener('message', e => {
    Jimp.read(e.data).then((img) => {
      img
      .print(font, 10, 10, "Hello World!")
      .getBase64(Jimp.AUTO, (err, src) => {
        if (err) throw err;
        self.postMessage(src);
      });
    });
  });

})();

The following error is thrown:

jimp.js:2 Uncaught (in promise) Error: error parsing font document is not defined

Using latest version of jimp (0.22.12)

Originally posted by @av01d in #289 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationChanges only affect the documentationreleasedThis issue/pull request has been released.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions