{"record":{"id":"bd784a76c7e9a591","repo":"gchq/CyberChef","slug":"error-generating-image-err","errorCode":null,"errorMessage":"Error generating image. (${err})","messagePattern":"Error generating image\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/GenerateImage.mjs","lineNumber":181,"sourceCode":"\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 {\n            // see https://nodejs.org/docs/latest-v24.x/api/buffer.html#bufbyteoffset\n            // for why we can't just return result.buffer\n            const result = await image.getBuffer(JimpMime.png);\n            return result.buffer.slice(result.byteOffset, result.byteOffset + result.byteLength);\n        } catch (err) {\n            throw new OperationError(`Error generating image. (${err})`);\n        }\n    }\n\n    /**\n     * Displays the generated 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":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/GenerateImage.mjs#L163-L199","documentation":"Thrown by GenerateImage when Jimp's async getBuffer(JimpMime.png) fails during PNG encoding of the generated image. The underlying error is interpolated. PNG encoding can fail due to malformed image state, memory limits, or Jimp internal errors.","triggerScenarios":"An image with zero width or height (e.g. empty input), a Jimp internal error during buffer serialization, or an environment where the PNG encoder is unavailable/corrupted.","commonSituations":"Empty or near-empty input producing a degenerate image, or a Jimp dependency version mismatch in a Node packaging context.","solutions":["Check that the input is non-empty and produces a positive width/height (width arg > 0 and input length > 0).","Inspect the interpolated err for the Jimp-specific cause.","Verify the Jimp dependency version matches what the operation expects."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (!input.length || width < 1) {\n  // avoid degenerate image; do not call getBuffer\n}","typeGuard":null,"tryCatchPattern":"try {\n  const result = await image.getBuffer(JimpMime.png);\n  return result.buffer.slice(result.byteOffset, result.byteOffset + result.byteLength);\n} catch (err) {\n  throw new OperationError(`Error generating image. (${err})`);\n}","preventionTips":["Provide non-empty input and a positive width.","Verify the Jimp version matches the operation's expectations."],"tags":["image","jimp","png","encoding","runtime"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}