gchq/CyberChef · error · OperationError

Error loading font. (${err})

Error message

Error loading font. (${err})

What it means

After the font assets resolve, AddTextToImage calls loadFont(self.docURL + '/' + font.default) to load and decode the bitmap font for rendering. If loadFont rejects (bad URL, undecodable .fnt/.png, or a worker-context URL resolution issue), the operation wraps the underlying error.

Source

Thrown at src/core/operations/AddTextToImage.mjs:219

                            const newBlue =
                                page.bitmap.data[idx + 2] - (255 - blue);
                            const newAlpha =
                                page.bitmap.data[idx + 3] - (255 - alpha);

                            // Make sure the bitmap values don't go below 0 as that makes jimp very unhappy
                            page.bitmap.data[idx] = newRed > 0 ? newRed : 0;
                            page.bitmap.data[idx + 1] =
                                newGreen > 0 ? newGreen : 0;
                            page.bitmap.data[idx + 2] =
                                newBlue > 0 ? newBlue : 0;
                            page.bitmap.data[idx + 3] =
                                newAlpha > 0 ? newAlpha : 0;
                        }
                    }
                }
            });
        } catch (err) {
            throw new OperationError(`Error loading font. (${err})`);
        }

        try {
            // Create a temporary image to hold the rendered text
            const textImage = new Jimp({
                width: measureText(jimpFont, text),
                height: measureTextHeight(jimpFont, text),
            });
            textImage.print({
                font: jimpFont,
                x: 0,
                y: 0,
                text,
            });

            // Scale the rendered text image to the correct size
            const scaleFactor = size / 72;
            if (size !== 1) {

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Run the operation in the standard CyberChef web/worker environment where self.docURL is set.
  2. Confirm the bmfont .fnt and its referenced .png pages are deployed and reachable.
  3. Rebuild so font paths resolve under the configured base URL.

Example fix

// before: self.docURL undefined → loadFont('/undefined/Roboto72White.fnt') rejects
// after: ensure the host sets self.docURL to the app base URL before invoking the op
Defensive patterns

Strategy: try-catch

Validate before calling

function assertDocUrl() {
  if (!self || !self.docURL) throw new Error('self.docURL must be set before AddTextToImage');
}

Try / catch

try {
  await addTextToImage(input, ...);
} catch (e) {
  if (/Error loading font/.test(e.message)) {
    // ensure self.docURL is set and bmfont pages are reachable
    throw new Error('Bitmap font failed to load — verify self.docURL and font asset URLs');
  }
  throw e;
}

Prevention

When it happens

Trigger: The constructed font URL (self.docURL + font path) does not resolve to a valid Jimp-loadable bitmap font; the .fnt references page PNGs that fail to load; self.docURL is unset/misconfigured in the worker so the URL is wrong.

Common situations: self.docURL not set correctly in a non-standard embedding of CyberChef; font PNG missing or corrupted; running the op outside the normal web/worker context where docURL is undefined.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/b52578365387371e. Report an issue: GitHub.