{"record":{"id":"e96dfa643a189510","repo":"gchq/CyberChef","slug":"error-exporting-image-err","errorCode":null,"errorMessage":"Error exporting image. (${err})","messagePattern":"Error exporting image\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/AddTextToImage.mjs","lineNumber":296,"sourceCode":"            image.blit({\n                src: textImage,\n                x: xPos,\n                y: yPos,\n            });\n        } catch (err) {\n            throw new OperationError(`Error adding text to image. (${err})`);\n        }\n\n        try {\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 exporting image. (${err})`);\n        }\n    }\n\n    /**\n     * Displays the blurred image using HTML for web apps\n     *\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","sourceCodeStart":278,"sourceCodeEnd":314,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/AddTextToImage.mjs#L278-L314","documentation":"After compositing, AddTextToImage exports the result via image.getBuffer — as PNG if the source was a GIF (Jimp cannot re-encode GIF), otherwise in the source's native MIME. Any export failure (unsupported output format, Jimp encode error, or memory issue) is caught and rethrown as 'Error exporting image.'","triggerScenarios":"getBuffer rejects: source MIME is a format Jimp can read but not encode (other than the GIF→PNG special case), the bitmap is in an unsupported color model for export, or an internal Jimp encode error occurs.","commonSituations":"Source was a BMP/TIFF that Jimp decoded but cannot re-encode; corrupted internal bitmap state after blit; very large image exhausting memory on encode.","solutions":["Re-export the source as PNG or JPEG so the output format is well-supported.","Reduce image dimensions if memory is the issue.","Confirm Jimp-omega supports writing the target format."],"exampleFix":"// before: source BMP that Jimp can read but cannot encode → 'Error exporting image.'\n// after: convert source to PNG upstream, then AddTextToImage","handlingStrategy":"try-catch","validationCode":"const JIMP_WRITABLE = new Set(['image/png', 'image/jpeg']);\nfunction assertWritable(mime) {\n  if (!JIMP_WRITABLE.has(mime)) throw new Error(`Jimp cannot re-encode ${mime}; convert to PNG upstream`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await addTextToImage(input, ...);\n} catch (e) {\n  if (/Error exporting image/.test(e.message)) {\n    // re-export source as PNG/JPEG upstream\n    throw new Error('Image export failed — convert source to a Jimp-writable format');\n  }\n  throw e;\n}","preventionTips":["Prefer PNG/JPEG sources so the output format is writable.","Reduce oversized images if memory is constrained.","Avoid formats Jimp can decode-but-not-encode (some BMP/TIFF)."],"tags":["image","jimp","export","encode"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}