gchq/CyberChef · warning · OperationError

Error adjusting image brightness or contrast. (${err})

Error message

Error adjusting image brightness or contrast. (${err})

What it means

Thrown by the inner try/catch of Image Brightness/Contrast when either the brightness()/contrast() mutation or the final getBuffer() fails. Wraps the underlying Jimp/runtime error so the operation surfaces a readable message rather than an unhandled rejection.

Source

Thrown at src/core/operations/ImageBrightnessContrast.mjs:86

                if (isWorkerEnvironment())
                    self.sendStatusMessage("Changing image brightness...");
                image.brightness(brightness / 100);
            }
            if (contrast !== 0) {
                if (isWorkerEnvironment())
                    self.sendStatusMessage("Changing image contrast...");
                image.contrast(contrast / 100);
            }

            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 brightness or contrast. (${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. Read the interpolated error to identify mutation vs buffer stage.
  2. Use moderate brightness/contrast values within [-100, 100].
  3. Downscale very large images before invoking, or run outside a worker.
  4. Update/roll back the jimp dependency if a codec bug is suspected.

Example fix

// before: extreme contrast drives a Jimp throw
op.run(buf, [0, 500]);
// after: stay within the documented range
op.run(buf, [0, 50]);
Defensive patterns

Strategy: validation

Validate before calling

function assertBrightnessContrastRange(b, c) {
  if (!Number.isFinite(b) || Math.abs(b) > 100) throw new RangeError(`brightness out of range: ${b}`);
  if (!Number.isFinite(c) || Math.abs(c) > 100) throw new RangeError(`contrast out of range: ${c}`);
}

Type guard

function isValidBrightnessContrast(b, c) {
  return [b, c].every(v => Number.isFinite(v) && Math.abs(v) <= 100);
}

Try / catch

try {
  result = await brightness.run(buf, [b, c]);
} catch (e) {
  if (e instanceof OperationError && /brightness or contrast/i.test(e.message)) {
    // clamp to a safe range and retry
    result = await brightness.run(buf, [Math.clamp(b,-100,100), Math.clamp(c,-100,100)]);
  } else throw e;
}

Prevention

When it happens

Trigger: brightness/contrast values that drive pixels out of representable range in a Jimp version that throws on overflow; getBuffer rejecting for an unsupported output mime; a worker environment memory error during processing of a very large image.

Common situations: Extreme argument values (brightness/contrast far outside [-100,100]); processing a huge image in a memory-constrained web worker; a Jimp regression where gif->png conversion fails.

Related errors


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