{"record":{"id":"1f0f377af105ad93","repo":"gchq/CyberChef","slug":"error-loading-image-err-1f0f37","errorCode":null,"errorMessage":"Error loading image. (${err})","messagePattern":"Error loading image\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/CoverImage.mjs","lineNumber":111,"sourceCode":"\n        const alignMap = {\n            Left: HorizontalAlign.LEFT,\n            Center: HorizontalAlign.CENTER,\n            Right: HorizontalAlign.RIGHT,\n            Top: VerticalAlign.TOP,\n            Middle: VerticalAlign.MIDDLE,\n            Bottom: VerticalAlign.BOTTOM,\n        };\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        try {\n            if (isWorkerEnvironment())\n                self.sendStatusMessage(\"Covering image...\");\n            image.cover({\n                w: width,\n                h: height,\n                align: alignMap[hAlign] | alignMap[vAlign],\n                mode: resizeMap[alg],\n            });\n            let imageBuffer;\n            if (image.mime === \"image/gif\") {\n                imageBuffer = await image.getBuffer(JimpMime.png);\n            } else {\n                imageBuffer = await image.getBuffer(image.mime);\n            }\n            return imageBuffer.buffer;\n        } catch (err) {","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/CoverImage.mjs#L93-L129","documentation":"After isImage() accepts the input, Cover Image calls Jimp.read(input) to decode. If decoding fails (corrupt/truncated data, structurally invalid image, or a format this Jimp version can't read), the error is wrapped as 'Error loading image.' The type sniff passed but the actual decode did not.","triggerScenarios":"Truncated payload; valid header but broken body; sub-format/color space Jimp can't decode; Jimp version lacking the codec.","commonSituations":"Incomplete download; exotic re-exported variant; dependency upgrade changing supported formats.","solutions":["Re-save the source as a standard PNG or baseline JPEG.","Verify file completeness and integrity.","Check the bundled Jimp version's supported formats.","Transcode exotic formats to PNG externally first."],"exampleFix":"// before: header-valid but body-corrupt input\n// after: supply a complete, valid image file","handlingStrategy":"try-catch","validationCode":"import { isImage } from \"src/core/lib/FileType.mjs\";\n// Reduces (not eliminates) the chance before Jimp.read.\nconst bytes = input instanceof ArrayBuffer ? new Uint8Array(input) : input;\nif (!isImage(bytes)) {\n  throw new Error(\"Not a recognized image — Jimp.read would likely fail.\");\n}","typeGuard":"import { isImage } from \"src/core/lib/FileType.mjs\";\nfunction isLikelyDecodableImage(buf) {\n  const bytes = buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf;\n  return isImage(bytes) !== false;\n}","tryCatchPattern":"try {\n  result = await coverImage.run(input, args);\n} catch (err) {\n  if (/Error loading image/.test(err.message)) {\n    // isImage passed but Jimp decode failed: re-export source as PNG/baseline JPEG, then retry.\n  }\n  throw err;\n}","preventionTips":["isImage passing does not guarantee Jimp can decode — verify integrity separately.","Prefer standard PNG/baseline JPEG sources.","Re-test supported formats after any Jimp upgrade."],"tags":["cyberchef","image","jimp","decode","operation-error"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}