gchq/CyberChef · error · OperationError

Error adding text to image. (${err})

Error message

Error adding text to image. (${err})

What it means

AddTextToImage measures the text, prints it onto a temporary Jimp image, computes x/y placement, then blits that text image onto the source with image.blit(...). Any failure in measure/print/blit — out-of-bounds coordinates, a zero-size text image, or a Jimp internal error — is caught and rethrown as 'Error adding text to image.'

Source

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

                case "Top":
                    yPos = 0;
                    break;
                case "Middle":
                    yPos = image.height / 2 - textImage.height / 2;
                    break;
                case "Bottom":
                    yPos = image.height - textImage.height;
                    break;
            }

            // Blit the rendered text image onto the original source image
            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
     *

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Provide non-empty text and sane x/y within the source image bounds.
  2. If using absolute positioning, ensure 0 ≤ x ≤ width and 0 ≤ y ≤ height after alignment.
  3. Confirm the fontFace value matches one of the four bundled fonts.

Example fix

// before: xPos=9999 on a 200x200 image, empty text → blit fails
// after: keep coordinates in-bounds and supply non-empty text
Defensive patterns

Strategy: try-catch

Validate before calling

function clampPosition(img, x, y, w, h) {
  if (x < 0 || y < 0 || x + w > img.width || y + h > img.height) {
    throw new Error('Text position out of image bounds');
  }
}

Try / catch

try {
  await addTextToImage(input, ...);
} catch (e) {
  if (/Error adding text to image/.test(e.message)) {
    // fix coordinates/text and retry
    throw new Error('Text rendering/placement failed — check coordinates, text, and fontFace');
  }
  throw e;
}

Prevention

When it happens

Trigger: x/y position arguments place the blit outside image bounds in a way Jimp rejects; the text image has zero width/height (empty text or measurement failure); an incompatible Jimp bitmap format between text image and source.

Common situations: Absolute x/y larger than image dimensions combined with a large font; empty text string producing a degenerate text image; hAlign/vAlign plus a negative offset pushing coordinates out of range.

Related errors


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