gchq/CyberChef · error · OperationError
Error converting image format. (${err})
Error message
Error converting image format. (${err}) What it means
Convert Image Format's transcode step calls image.getBuffer(mime, options) for the selected target format (with jpeg quality, PNG filter/deflate settings, or defaults). Any encode failure is caught and re-thrown as 'Error converting image format.' Causes include an unsupported target format, out-of-range encoder options, or source content the target codec cannot represent.
Source
Thrown at src/core/operations/ConvertImageFormat.mjs:114
case JimpMime.jpeg:
buffer = await image.getBuffer(mime, {
quality: jpegQuality,
});
break;
case JimpMime.png:
buffer = await image.getBuffer(mime, {
filterType: pngFilterMap[pngFilterType],
deflateLevel: pngDeflateLevel,
});
break;
default:
buffer = await image.getBuffer(mime);
break;
}
return buffer.buffer;
} catch (err) {
throw new OperationError(`Error converting image format. (${err})`);
}
}
/**
* Displays the converted image using HTML for web apps
*
* @param {ArrayBuffer} data
* @returns {html}
*/
present(data) {
if (!data.byteLength) return "";
const dataArray = new Uint8Array(data);
const type = isImage(dataArray);
if (!type) {
throw new OperationError("Invalid file type.");
}
View on GitHub (pinned to 4290ea7539)
Solutions
- Choose a well-supported target format (PNG or JPEG).
- Keep jpegQuality within 1–100 and PNG deflate/filter at defaults unless you know the valid ranges.
- If conversion fails, fall back to PNG (lossless, broad support) and retry.
- Check the bundled Jimp version supports the chosen output codec.
Example fix
// before: jpegQuality passed as 0 or >100 const args = [..., 0, ...]; // after const args = [..., 85, ...]; // valid JPEG quality
Defensive patterns
Strategy: try-catch
Validate before calling
function validEncodeArgs(format, jpegQuality, pngDeflateLevel) {
if (!format) return false;
if (format === "JPEG" && !(jpegQuality >= 1 && jpegQuality <= 100)) return false;
if (format === "PNG" && !(Number.isInteger(pngDeflateLevel) && pngDeflateLevel >= 0 && pngDeflateLevel <= 9)) return false;
return true;
}
if (!validEncodeArgs(format, jpegQuality, pngDeflateLevel)) {
throw new Error("Invalid encoder arguments for target format.");
} Type guard
function isJpegQuality(v) {
return typeof v === "number" && v >= 1 && v <= 100;
} Try / catch
try {
result = await convertImageFormat.run(input, args);
} catch (err) {
if (/Error converting image format/.test(err.message)) {
// Encode failed: try PNG with defaults as a broadly-supported fallback.
}
throw err;
} Prevention
- Prefer PNG or JPEG as the target format for broadest codec support.
- Keep jpegQuality in 1–100 and PNG deflate/filter at defaults unless you know valid ranges.
- After a Jimp upgrade, re-confirm your target formats still encode.
When it happens
Trigger: Target format not supported by the bundled Jimp; jpegQuality outside 1–100; PNG deflateLevel/filterType invalid; encoding a source (e.g. with alpha) into a format that can't represent it; CMYK source into JPEG.
Common situations: Misconfigured encoder arguments; Jimp version differences in codec support; edge-case source images.
Related errors
- Invalid file type.
- Error loading image. (${err})
- Error containing image. (${err})
- Invalid file format.
- Error opening image file. (${err})
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/7fa43d1ad519a555.
Report an issue: GitHub.