{"record":{"id":"b52578365387371e","repo":"gchq/CyberChef","slug":"error-loading-font-err","errorCode":null,"errorMessage":"Error loading font. (${err})","messagePattern":"Error loading font\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/AddTextToImage.mjs","lineNumber":219,"sourceCode":"                            const newBlue =\n                                page.bitmap.data[idx + 2] - (255 - blue);\n                            const newAlpha =\n                                page.bitmap.data[idx + 3] - (255 - alpha);\n\n                            // Make sure the bitmap values don't go below 0 as that makes jimp very unhappy\n                            page.bitmap.data[idx] = newRed > 0 ? newRed : 0;\n                            page.bitmap.data[idx + 1] =\n                                newGreen > 0 ? newGreen : 0;\n                            page.bitmap.data[idx + 2] =\n                                newBlue > 0 ? newBlue : 0;\n                            page.bitmap.data[idx + 3] =\n                                newAlpha > 0 ? newAlpha : 0;\n                        }\n                    }\n                }\n            });\n        } catch (err) {\n            throw new OperationError(`Error loading font. (${err})`);\n        }\n\n        try {\n            // Create a temporary image to hold the rendered text\n            const textImage = new Jimp({\n                width: measureText(jimpFont, text),\n                height: measureTextHeight(jimpFont, text),\n            });\n            textImage.print({\n                font: jimpFont,\n                x: 0,\n                y: 0,\n                text,\n            });\n\n            // Scale the rendered text image to the correct size\n            const scaleFactor = size / 72;\n            if (size !== 1) {","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/AddTextToImage.mjs#L201-L237","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run the operation in the standard CyberChef web/worker environment where self.docURL is set.","Confirm the bmfont .fnt and its referenced .png pages are deployed and reachable.","Rebuild so font paths resolve under the configured base URL."],"exampleFix":"// before: self.docURL undefined → loadFont('/undefined/Roboto72White.fnt') rejects\n// after: ensure the host sets self.docURL to the app base URL before invoking the op","handlingStrategy":"try-catch","validationCode":"function assertDocUrl() {\n  if (!self || !self.docURL) throw new Error('self.docURL must be set before AddTextToImage');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await addTextToImage(input, ...);\n} catch (e) {\n  if (/Error loading font/.test(e.message)) {\n    // ensure self.docURL is set and bmfont pages are reachable\n    throw new Error('Bitmap font failed to load — verify self.docURL and font asset URLs');\n  }\n  throw e;\n}","preventionTips":["Run the op in the standard web/worker context where self.docURL is set.","Ensure the .fnt and referenced .png pages are deployed.","Validate font asset URLs resolve under the base URL."],"tags":["image","jimp","fonts","loading"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}