gchq/CyberChef · error · OperationError

Error exporting image. (${err})

Error message

Error exporting image. (${err})

What it means

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.'

Source

Thrown at src/core/operations/AddTextToImage.mjs:296

            image.blit({
                src: textImage,
                x: xPos,
                y: yPos,
            });
        } catch (err) {
            throw new OperationError(`Error adding text to image. (${err})`);
        }

        try {
            let imageBuffer;
            if (image.mime === "image/gif") {
                imageBuffer = await image.getBuffer(JimpMime.png);
            } else {
                imageBuffer = await image.getBuffer(image.mime);
            }
            return imageBuffer.buffer;
        } catch (err) {
            throw new OperationError(`Error exporting image. (${err})`);
        }
    }

    /**
     * Displays the blurred image using HTML for web apps
     *
     * @param {ArrayBuffer} data
     * @returns {html}
     */
    present(data) {
        if (!data.byteLength) return "";
        const dataArray = new Uint8Array(data);

        const type = isImage(dataArray);
        if (!type) {
            throw new OperationError("Invalid file type.");
        }

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Re-export the source as PNG or JPEG so the output format is well-supported.
  2. Reduce image dimensions if memory is the issue.
  3. Confirm Jimp-omega supports writing the target format.

Example fix

// before: source BMP that Jimp can read but cannot encode → 'Error exporting image.'
// after: convert source to PNG upstream, then AddTextToImage
Defensive patterns

Strategy: try-catch

Validate before calling

const JIMP_WRITABLE = new Set(['image/png', 'image/jpeg']);
function assertWritable(mime) {
  if (!JIMP_WRITABLE.has(mime)) throw new Error(`Jimp cannot re-encode ${mime}; convert to PNG upstream`);
}

Try / catch

try {
  await addTextToImage(input, ...);
} catch (e) {
  if (/Error exporting image/.test(e.message)) {
    // re-export source as PNG/JPEG upstream
    throw new Error('Image export failed — convert source to a Jimp-writable format');
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13). Data as JSON: /api/errors/e96dfa643a189510. Report an issue: GitHub.