{"record":{"id":"5ddf8a4c5d22370c","repo":"gchq/CyberChef","slug":"error-normalising-image-err-5ddf8a","errorCode":null,"errorMessage":"Error normalising image. (${err})","messagePattern":"Error normalising image\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/NormaliseImage.mjs","lineNumber":61,"sourceCode":"        let image;\n        try {\n            image = await Jimp.read(input);\n        } catch (err) {\n            throw new OperationError(`Error opening image file. (${err})`);\n        }\n\n        try {\n            image.normalize();\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 normalising image. (${err})`);\n        }\n    }\n\n    /**\n     * Displays the normalised image using HTML for web apps\n     * @param {ArrayBuffer} data\n     * @returns {html}\n     */\n    present(data) {\n        if (!data.byteLength) return \"\";\n        const dataArray = new Uint8Array(data);\n\n        const type = isImage(dataArray);\n        if (!type) {\n            throw new OperationError(\"Invalid file type.\");\n        }\n\n        return `<img src=\"data:${type};base64,${toBase64(dataArray)}\">`;","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/NormaliseImage.mjs#L43-L79","documentation":"Thrown by NormaliseImage.run when image.normalize() or image.getBuffer() throws after a successful Jimp.read. The image decoded but colour-normalisation or re-encoding failed — often due to an unsupported colour mode, an empty pixel buffer, or an encoding bug in Jimp. The original error is interpolated.","triggerScenarios":"run(input, args) reaching the second try-block where Jimp successfully parsed the image but normalize() or getBuffer() rejects. Triggers include 1-bit or 16-bit PNGs Jimp mishandles, animated-GIF frame issues, or an internal Jimp version incompatibility.","commonSituations":"Jimp version mismatch after a dependency upgrade; exotic bit-depth or colour-profile image; animated GIF (the code special-cases GIF→PNG for this reason); image with an alpha channel Jimp cannot normalise; very large image exhausting memory during normalisation.","solutions":["Convert the source image to a standard 8-bit sRGB PNG/JPG with another tool first.","Check the Jimp version matches what CyberChef expects (see package.json).","Read the interpolated err to identify whether normalize() or getBuffer() failed.","For animated GIFs, extract a single frame before normalising."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await chef.bake(\"Normalise Image\", [], input);\n} catch (e) {\n  if (e.message.startsWith(\"Error normalising image.\")) {\n    // convert source to standard 8-bit sRGB and retry\n  } else throw e;\n}","preventionTips":["Pre-convert unusual bit-depths/colour-profiles to 8-bit sRGB.","Keep Jimp version aligned with CyberChef's package.json.","Extract a single frame from animated GIFs before normalising."],"tags":["image","jimp","encode-error","dependency"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}