{"record":{"id":"83eb686f6c800542","repo":"gchq/CyberChef","slug":"error-while-generating-image-from-pixel-values","errorCode":null,"errorMessage":"Error while generating image from pixel values. (${err})","messagePattern":"Error while generating image from pixel values\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/GenerateImage.mjs","lineNumber":157,"sourceCode":"                        blue = input[i++];\n                        break;\n\n                    case \"RGBA\":\n                        red = input[i++];\n                        green = input[i++];\n                        blue = input[i++];\n                        alpha = input[i++];\n                        break;\n\n                    default:\n                        throw new OperationError(`Unsupported Mode: (${mode})`);\n                }\n\n                try {\n                    const pixel = rgbaToInt(red, green, blue, alpha);\n                    image.setPixelColor(pixel, x, y);\n                } catch (err) {\n                    throw new OperationError(\n                        `Error while generating image from pixel values. (${err})`,\n                    );\n                }\n            }\n        }\n\n        if (scale !== 1) {\n            if (isWorkerEnvironment())\n                self.sendStatusMessage(\"Scaling image...\");\n\n            image.scaleToFit({\n                w: width * scale,\n                h: height * scale,\n                mode: ResizeStrategy.NEAREST_NEIGHBOR,\n            });\n        }\n\n        try {","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/GenerateImage.mjs#L139-L175","documentation":"Thrown when Jimp's rgbaToInt() or image.setPixelColor() raises during per-pixel image construction in GenerateImage. The original error is interpolated into the message. This typically means a color component value was outside the 0-255 range or a coordinate was out of bounds.","triggerScenarios":"A computed red/green/blue/alpha value falling outside [0,255], or setPixelColor receiving (x,y) beyond the image dimensions. Can also occur if the input byte interpretation yields unexpected values after mode-specific packing.","commonSituations":"Corrupt or truncated input that leaves a partial pixel at the end, or a Jimp version change tightening value validation.","solutions":["Inspect the interpolated err text to identify which value was out of range.","Ensure input length is an exact multiple of bytesPerPixel (see error 382) so no partial pixel is read.","Update or pin the Jimp dependency if a version regression tightened validation."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  const pixel = rgbaToInt(red, green, blue, alpha);\n  image.setPixelColor(pixel, x, y);\n} catch (err) {\n  throw new OperationError(`Error while generating image from pixel values. (${err})`);\n}","preventionTips":["Ensure input length is an exact multiple of bytesPerPixel.","Pin the Jimp dependency version to avoid validation regressions."],"tags":["image","jimp","pixel","runtime"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}