gchq/CyberChef · error · OperationError

Error loading image. (${err})

Error message

Error loading image. (${err})

What it means

After isImage() accepts the input, Crop Image calls Jimp.read(input) to decode. If decoding fails (corrupt/truncated data, structurally invalid image, or a format this Jimp version can't read), the error is wrapped as 'Error loading image.' The type sniff passed but the actual decode did not.

Source

Thrown at src/core/operations/CropImage.mjs:114

            xPos,
            yPos,
            width,
            height,
            autocrop,
            autoTolerance,
            autoFrames,
            autoSymmetric,
            autoBorder,
        ] = 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 (isWorkerEnvironment())
                self.sendStatusMessage("Cropping image...");
            if (autocrop) {
                image.autocrop({
                    tolerance: autoTolerance / 100,
                    cropOnlyFrames: autoFrames,
                    cropSymmetric: autoSymmetric,
                    leaveBorder: autoBorder,
                });
            } else {
                image.crop({
                    x: xPos,
                    y: yPos,
                    w: width,
                    h: height,
                });

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Re-save the source as a standard PNG or baseline JPEG.
  2. Verify file completeness and integrity.
  3. Check the bundled Jimp version's supported formats.
  4. Transcode exotic formats to PNG externally first.

Example fix

// before: corrupt input that isImage accepts but Jimp rejects
// after: supply a complete, valid image file
Defensive patterns

Strategy: try-catch

Validate before calling

import { isImage } from "src/core/lib/FileType.mjs";
// Reduces (not eliminates) the chance before Jimp.read.
const bytes = input instanceof ArrayBuffer ? new Uint8Array(input) : input;
if (!isImage(bytes)) {
  throw new Error("Not a recognized image — Jimp.read would likely fail.");
}

Type guard

import { isImage } from "src/core/lib/FileType.mjs";
function isLikelyDecodableImage(buf) {
  const bytes = buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf;
  return isImage(bytes) !== false;
}

Try / catch

try {
  result = await cropImage.run(input, args);
} catch (err) {
  if (/Error loading image/.test(err.message)) {
    // isImage passed but Jimp decode failed: re-export source as PNG/baseline JPEG, then retry.
  }
  throw err;
}

Prevention

When it happens

Trigger: Truncated payload; valid header but broken body; sub-format/color space Jimp can't decode; Jimp version lacking the codec.

Common situations: Incomplete download; exotic re-exported variant; dependency upgrade changing supported formats.

Related errors


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