{"record":{"id":"9fd6b9140fbe59c7","repo":"gchq/CyberChef","slug":"error-loading-image-err-9fd6b9","errorCode":null,"errorMessage":"Error loading image. (${err})","messagePattern":"Error loading image\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/CropImage.mjs","lineNumber":114,"sourceCode":"            xPos,\n            yPos,\n            width,\n            height,\n            autocrop,\n            autoTolerance,\n            autoFrames,\n            autoSymmetric,\n            autoBorder,\n        ] = args;\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(\"Cropping image...\");\n            if (autocrop) {\n                image.autocrop({\n                    tolerance: autoTolerance / 100,\n                    cropOnlyFrames: autoFrames,\n                    cropSymmetric: autoSymmetric,\n                    leaveBorder: autoBorder,\n                });\n            } else {\n                image.crop({\n                    x: xPos,\n                    y: yPos,\n                    w: width,\n                    h: height,\n                });","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/CropImage.mjs#L96-L132","documentation":"After isImage() accepts the input, Crop 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: corrupt input that isImage accepts but Jimp rejects\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 cropImage.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"}