gchq/CyberChef · warning · OperationError

Error applying filter to image. (${err})

Error message

Error applying filter to image. (${err})

What it means

Wraps any error from the greyscale()/sepia() filter call or the subsequent getBuffer() inside Image Filter's inner try/catch. Surfaces the underlying Jimp error in the message so the user can tell whether filtering or encoding failed.

Source

Thrown at src/core/operations/ImageFilter.mjs:78

                    "Applying " +
                        filterType.toLowerCase() +
                        " filter to image...",
                );
            if (filterType === "Greyscale") {
                image.greyscale();
            } else {
                image.sepia();
            }

            let imageBuffer;
            if (image.mime === "image/gif") {
                imageBuffer = await image.getBuffer(JimpMime.png);
            } else {
                imageBuffer = await image.getBuffer(image.mime);
            }
            return imageBuffer.buffer;
        } catch (err) {
            throw new OperationError(
                `Error applying filter to image. (${err})`,
            );
        }
    }

    /**
     * Displays the blurred 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

  1. Read the embedded error to distinguish filter vs buffer failure.
  2. Pre-convert exotic colour spaces/bit depths to 8-bit RGB PNG/JPEG.
  3. Downscale large images or process outside a worker.
  4. Try the other filter type to isolate a codec-specific bug.

Example fix

// before: 16-bit CMYK JPEG trips the filter
op.run(cmykJpegBuf, ["Greyscale"]);
// after: convert to 8-bit sRGB first
op.run(srgbPngBuf, ["Greyscale"]);
Defensive patterns

Strategy: fallback

Validate before calling

function assertFilterType(t) {
  if (!['Greyscale', 'Sepia'].includes(t)) {
    throw new RangeError(`Unsupported filter type: ${t}`);
  }
}

Type guard

function isSupportedFilterType(t) {
  return t === 'Greyscale' || t === 'Sepia';
}

Try / catch

try {
  result = await filter.run(buf, [filterType]);
} catch (e) {
  if (e instanceof OperationError && /applying filter/i.test(e.message)) {
    // try the other filter, or pre-convert colour space
    result = await filter.run(await toSrgbPng(buf), [filterType]);
  } else throw e;
}

Prevention

When it happens

Trigger: Jimp filter rejecting on an unusual colour space or bit depth; getBuffer failing for an unsupported output mime; memory exhaustion on a large image in a worker; a Jimp regression in sepia/greyscale.

Common situations: 16-bit or CMYK JPEG that Jimp mishandles; animated GIF where frame handling throws; oversized image; Jimp version bug.

Related errors


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