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
- Re-save the source as a standard PNG or baseline JPEG.
- Verify file completeness and integrity.
- Check the bundled Jimp version's supported formats.
- 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
- isImage passing does not guarantee Jimp can decode — verify integrity separately.
- Prefer standard PNG/baseline JPEG sources.
- Re-test supported formats after any Jimp upgrade.
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
- Error loading image. (${err})
- Error opening image file. (${err})
- Error loading image. (${err})
- Invalid file type.
- Error containing image. (${err})
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/9fd6b9140fbe59c7.
Report an issue: GitHub.