gchq/CyberChef · warning · OperationError

Error loading image.

Error message

Error loading image. (${err})

What it means

Thrown when Jimp.read(input) rejects while loading the image inside Image Brightness/Contrast. This fires only after isImage passed, so the magic bytes looked plausible but the actual decode failed. The original Jimp error is interpolated into the message.

Solutions

  1. Read the interpolated Jimp error for the specific failure reason.
  2. Re-export or re-download the source image to ensure it is complete and uncorrupted.
  3. Convert the image to PNG/JPEG with an external tool before invoking.
  4. Check the bundled Jimp version supports the image's subformat.

Example fix

// before: feeding a truncated buffer whose header survived but body did not
op.run(truncatedPngBuf, [10, 10]);
// after: feed the complete file
op.run(completePngBuf, [10, 10]);
Defensive patterns

Strategy: try-catch

Validate before calling

async function assertJimpReadable(buf) {
  try { await Jimp.read(buf); }
  catch (e) { throw new Error(`Jimp cannot read this image: ${e}`); }
}

Try / catch

try {
  result = await brightness.run(buf, [b, c]);
} catch (e) {
  if (e instanceof OperationError && /Error loading image/.test(e.message)) {
    // re-supply a complete source image
    result = await brightness.run(await reload(fullUrl), [b, c]);
  } else throw e;
}

Prevention

When it happens

Trigger: Truncated image (magic bytes present but body incomplete); corrupt pixel data; a format Jimp does not support despite a sniffable header (e.g. some WebP/HEIC variants, progressive JPEG edge cases); a buffer that is actually a container (e.g. a SVG with PNG-like bytes).

Common situations: Partial download/capture; conversion artefact from another tool; version mismatch where the bundled Jimp lacks a codec; very large image exceeding Jimp's memory.

Related errors


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

Appendix: source

Thrown at src/core/operations/ImageBrightnessContrast.mjs:64

        ];
    }

    /**
     * @param {ArrayBuffer} input
     * @param {Object[]} args
     * @returns {byteArray}
     */
    async run(input, args) {
        const [brightness, contrast] = args;
        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})`);
        }
        try {
            if (brightness !== 0) {
                if (isWorkerEnvironment())
                    self.sendStatusMessage("Changing image brightness...");
                image.brightness(brightness / 100);
            }
            if (contrast !== 0) {
                if (isWorkerEnvironment())
                    self.sendStatusMessage("Changing image contrast...");
                image.contrast(contrast / 100);
            }

            let imageBuffer;
            if (image.mime === "image/gif") {
                imageBuffer = await image.getBuffer(JimpMime.png);
            } else {
                imageBuffer = await image.getBuffer(image.mime);

View on GitHub (pinned to 4290ea7539)