{"record":{"id":"21a2a289607ce356","repo":"gchq/CyberChef","slug":"error-loading-image-err-21a2a2","errorCode":null,"errorMessage":"Error loading image. (${err})","messagePattern":"Error loading image\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/ImageOpacity.mjs","lineNumber":57,"sourceCode":"        ];\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {byteArray}\n     */\n    async run(input, args) {\n        const [opacity] = 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(\"Changing image opacity...\");\n            image.opacity(opacity / 100);\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) {\n            throw new OperationError(`Error changing image opacity. (${err})`);\n        }\n    }\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/ImageOpacity.mjs#L39-L75","documentation":"Wraps any failure of Jimp.read(input) inside ImageOpacity.run(). The signature passed isImage but Jimp could not decode the body (truncated, corrupt, unsupported codec). The original error is interpolated. OperationError surfaced as step output.","triggerScenarios":"isImage accepted the magic bytes but Jimp rejects the payload: truncated file, header present but body corrupt, or a codec Jimp does not ship. An ArrayBuffer shorter than the header declares is a common cause.","commonSituations":"Truncated copy-paste, image that browsers render but Jimp cannot, jimp version dropping a codec, valid signature around unrelated bytes.","solutions":["Read ${err} for Jimp's specific reason.","Re-save the source as PNG or JPEG and retry.","Confirm buffer length matches the declared image dimensions.","Verify the installed jimp supports the codec."],"exampleFix":"// before\nopacityOp.run(truncatedPng, [50]); // -> Error loading image.\n// after\nconst buf = await reencodeToPng(truncatedPng);\nopacityOp.run(buf, [50]);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await opacityOp.run(buf, [opacity]);\n} catch (e) {\n  if (e instanceof OperationError && /Error loading image/.test(e.message)) {\n    reportCorruptImage(e.message);\n  } else throw e;\n}","preventionTips":["Re-encode untrusted images to PNG first.","Validate buffer length against the header.","Pin a known-good jimp version.","Surface Jimp's interpolated reason to the user."],"tags":["image","jimp","decoding","cyberchef","error-handling"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}