{"record":{"id":"68a041f55a440f8b","repo":"gchq/CyberChef","slug":"error-loading-image-err-68a041","errorCode":null,"errorMessage":"Error loading image. (${err})","messagePattern":"Error loading image\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ResizeImage.mjs","lineNumber":98,"sourceCode":"            resizeAlg = args[4];\n\n        const resizeMap = {\n            \"Nearest Neighbour\": ResizeStrategy.NEAREST_NEIGHBOR,\n            Bilinear: ResizeStrategy.BILINEAR,\n            Bicubic: ResizeStrategy.BICUBIC,\n            Hermite: ResizeStrategy.HERMITE,\n            Bezier: ResizeStrategy.BEZIER,\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 (unit === \"Percent\") {\n                width = image.width * (width / 100);\n                height = image.height * (height / 100);\n            }\n\n            if (isWorkerEnvironment())\n                self.sendStatusMessage(\"Resizing image...\");\n            if (aspect) {\n                image.scaleToFit({\n                    w: width,\n                    h: height,\n                    mode: resizeMap[resizeAlg],\n                });\n            } else {\n                image.resize({\n                    w: width,","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ResizeImage.mjs#L80-L116","documentation":"Thrown by ResizeImage when Jimp.read(input) throws — i.e. the bytes passed the isImage() signature check but Jimp could not decode them. The underlying Jimp error is wrapped into the message. This indicates a file that looks like an image by magic bytes but is malformed.","triggerScenarios":"Truncated or corrupt image (valid header but incomplete pixel data); a file with a spoofed image signature; an image using a sub-format Jimp's decoder rejects; an unsupported color space or compression.","commonSituations":"Partially downloaded images; files renamed to .png/.jpg without real conversion; images produced by non-standard encoders; memory-limit failures inside Jimp on very large images.","solutions":["Re-export/re-save the image with a standard tool (ImageMagick, Preview, Photoshop).","Re-download to rule out truncation.","For very large images, downscale externally first to avoid Jimp memory limits.","Inspect the wrapped err to see which decoder stage failed."],"exampleFix":"// before\n//   input: PNG header + truncated body -> Jimp throws\n// after\n//   input: complete, re-saved PNG that Jimp can decode","handlingStrategy":"try-catch","validationCode":"let ok; try { await Jimp.read(input); ok = true; } catch { ok = false; } if (!ok) throw new Error('Image will fail to decode');","typeGuard":"async function decodableByJimp(buf){ try { await Jimp.read(buf); return true; } catch { return false; } }","tryCatchPattern":"try { await resizeImage(input); } catch (e) { if (/Error loading image/.test(e.message)) reencodeImage(input); else throw e; }","preventionTips":["Re-encode images with standard tools before resizing.","Watch for truncation in large files.","Downscale huge images externally to avoid Jimp memory limits."],"tags":["image","resize","jimp","decode-error"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}