gchq/CyberChef · error · OperationError

Error loading image. (${err})

Error message

Error loading image. (${err})

What it means

After passing the isImage magic-byte check, AddTextToImage calls Jimp.read(input) to actually decode the image. If Jimp cannot decode the bytes (unsupported codec, truncated file, or a format Jimp-omega does not support), the promise rejects and the operation rethrows the underlying error wrapped in OperationError.

Source

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

            size = args[5],
            fontFace = args[6],
            red = args[7],
            green = args[8],
            blue = args[9],
            alpha = args[10];

        let xPos = args[3],
            yPos = args[4];

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

        let image;
        try {
            image = await Jimp.read(input);
        } catch (err) {
            throw new OperationError(`Error loading image. (${err})`);
        }

        if (isWorkerEnvironment())
            self.sendStatusMessage("Adding text to image...");

        const fontsMap = {};
        try {
            const fonts = [
                import(
                    /* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/Roboto72White.fnt"
                ),
                import(
                    /* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/RobotoBlack72White.fnt"
                ),
                import(
                    /* webpackMode: "eager" */ "../../web/static/fonts/bmfonts/RobotoMono72White.fnt"
                ),
                import(

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Re-export the source image as PNG or baseline JPEG with a mainstream tool.
  2. Confirm the file is complete (byte size matches the source).
  3. If the format is unusual (HEIC/AVIF/TIFF), convert it to PNG/JPEG upstream.

Example fix

// before: corrupt/truncated JPEG passes magic check but fails Jimp.read
// after: re-save the source as PNG, then run AddTextToImage
Defensive patterns

Strategy: try-catch

Validate before calling

async function canJimpDecode(bytes) {
  try { await Jimp.read(Buffer.from(bytes)); return true; } catch { return false; }
}

Try / catch

try {
  await addTextToImage(input, ...);
} catch (e) {
  if (/Error loading image/.test(e.message)) {
    // re-export source as PNG/baseline JPEG upstream
    throw new Error('Source image could not be decoded by Jimp');
  }
  throw e;
}

Prevention

When it happens

Trigger: Jimp.read throws despite a passing magic-byte check: file is truncated mid-stream, uses an unsupported color space or subformat, or a format Jimp cannot handle (e.g. some TIFF/HEIC/AVIF variants, or progressive JPEG edge cases).

Common situations: Corrupt download; image produced by an encoder Jimp does not fully support; partial file from a network cut-off; CMYK JPEG or exotic ICC profile.

Related errors


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