{"record":{"id":"14725d647931fa2c","repo":"gchq/CyberChef","slug":"error-loading-image-err","errorCode":null,"errorMessage":"Error loading image. (${err})","messagePattern":"Error loading image\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/AddTextToImage.mjs","lineNumber":134,"sourceCode":"            size = args[5],\n            fontFace = args[6],\n            red = args[7],\n            green = args[8],\n            blue = args[9],\n            alpha = args[10];\n\n        let xPos = args[3],\n            yPos = args[4];\n\n        if (!isImage(input)) {\n            throw new OperationError(\"Invalid file type.\");\n        }\n\n        let image;\n        try {\n            image = await Jimp.read(input);\n        } catch (err) {\n            throw new OperationError(`Error loading image. (${err})`);\n        }\n\n        if (isWorkerEnvironment())\n            self.sendStatusMessage(\"Adding text to image...\");\n\n        const fontsMap = {};\n        try {\n            const fonts = [\n                import(\n                    /* webpackMode: \"eager\" */ \"../../web/static/fonts/bmfonts/Roboto72White.fnt\"\n                ),\n                import(\n                    /* webpackMode: \"eager\" */ \"../../web/static/fonts/bmfonts/RobotoBlack72White.fnt\"\n                ),\n                import(\n                    /* webpackMode: \"eager\" */ \"../../web/static/fonts/bmfonts/RobotoMono72White.fnt\"\n                ),\n                import(","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/AddTextToImage.mjs#L116-L152","documentation":"After passing the isImage magic-byte check, AddTextToImage calls Jimp.read(input) to actually decode the image. If Jimp cannot decode the bytes (unsupported codec, truncated file, or a format Jimp-omega does not support), the promise rejects and the operation rethrows the underlying error wrapped in OperationError.","triggerScenarios":"Jimp.read throws despite a passing magic-byte check: file is truncated mid-stream, uses an unsupported color space or subformat, or a format Jimp cannot handle (e.g. some TIFF/HEIC/AVIF variants, or progressive JPEG edge cases).","commonSituations":"Corrupt download; image produced by an encoder Jimp does not fully support; partial file from a network cut-off; CMYK JPEG or exotic ICC profile.","solutions":["Re-export the source image as PNG or baseline JPEG with a mainstream tool.","Confirm the file is complete (byte size matches the source).","If the format is unusual (HEIC/AVIF/TIFF), convert it to PNG/JPEG upstream."],"exampleFix":"// before: corrupt/truncated JPEG passes magic check but fails Jimp.read\n// after: re-save the source as PNG, then run AddTextToImage","handlingStrategy":"try-catch","validationCode":"async function canJimpDecode(bytes) {\n  try { await Jimp.read(Buffer.from(bytes)); return true; } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await addTextToImage(input, ...);\n} catch (e) {\n  if (/Error loading image/.test(e.message)) {\n    // re-export source as PNG/baseline JPEG upstream\n    throw new Error('Source image could not be decoded by Jimp');\n  }\n  throw e;\n}","preventionTips":["Prefer PNG or baseline JPEG sources.","Confirm the file is complete (matches source byte size).","Convert exotic formats (HEIC/AVIF/TIFF/CMYK JPEG) to PNG upstream."],"tags":["image","jimp","decode"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}