gchq/CyberChef · error · OperationError

Error adjusting image hue / saturation / lightness. (${err})

Error message

Error adjusting image hue / saturation / lightness. (${err})

What it means

Catches any exception thrown while applying hue/saturation/lightness via image.color/brightness or while getBuffer encodes the result, and re-throws it as an OperationError. GIF outputs are re-encoded as PNG (image.mime === 'image/gif' branch), so encoder errors here usually involve PNG. The interpolated err gives the Jimp-level cause.

Source

Thrown at src/core/operations/ImageHueSaturationLightness.mjs:115

                if (isWorkerEnvironment())
                    self.sendStatusMessage("Changing image lightness...");
                image.color([
                    {
                        apply: "lighten",
                        params: [lightness],
                    },
                ]);
            }

            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 adjusting image hue / saturation / lightness. (${err})`,
            );
        }
    }

    /**
     * Displays the 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. Clamp hue to [-360,360], saturation/lightness to [-100,100] before calling.
  2. Reduce the image size and retry to rule out memory/timeout.
  3. Re-encode the source to PNG so the GIF-to-PNG output branch is exercised cleanly.
  4. If err names a specific Jimp method, upgrade or pin jimp to a compatible version.

Example fix

// before
hslOp.run(png, [9999, NaN, -500]); // throws adjusting error
// after
const clamp = (v, lo, hi) => Math.max(lo, Math.min(hi, Number(v) || 0));
hslOp.run(png, [clamp(hue,-360,360), clamp(sat,-100,100), clamp(light,-100,100)]);
Defensive patterns

Strategy: validation

Validate before calling

const clamp = (v, lo, hi) => { const n = Number(v); return Number.isFinite(n) ? Math.max(lo, Math.min(hi, n)) : lo; };
const safeArgs = [clamp(hue, -360, 360), clamp(sat, -100, 100), clamp(light, -100, 100)];

Type guard

function isValidHSLArgs([h, s, l]) {
  return [h, s, l].every(v => Number.isFinite(Number(v)));
}

Prevention

When it happens

Trigger: Hue/saturation/lightness argument values outside Jimp's accepted numeric ranges, NaN produced by parsing, or getBuffer failing on an output mime Jimp cannot encode. Also fires on internal Jimp failures for very large images or unexpected pixel layouts.

Common situations: Argument sliders pushed to non-numeric/extreme values, a corrupted pixel buffer surviving Jimp.read, or memory pressure on a huge image during encode.

Related errors


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