gchq/CyberChef · error · OperationError

Error changing image opacity. (${err})

Error message

Error changing image opacity. (${err})

What it means

Catches any exception during image.opacity(opacity/100) or getBuffer and re-wraps it. opacity is divided by 100, so a non-numeric or out-of-range opacity yields NaN or a value Jimp rejects. GIF outputs are re-encoded as PNG. The interpolated err gives the Jimp cause.

Source

Thrown at src/core/operations/ImageOpacity.mjs:72

        try {
            image = await Jimp.read(input);
        } catch (err) {
            throw new OperationError(`Error loading image. (${err})`);
        }
        try {
            if (isWorkerEnvironment())
                self.sendStatusMessage("Changing image opacity...");
            image.opacity(opacity / 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 changing image opacity. (${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.");
        }

        return `<img src="data:${type};base64,${toBase64(dataArray)}">`;

View on GitHub (pinned to 4290ea7539)

Solutions

  1. Clamp opacity to [0,100] and coerce to a number before calling.
  2. Downscale the image and retry to rule out memory issues.
  3. Re-encode source to PNG so the GIF branch is clean.
  4. If err names a Jimp method, adjust jimp version.

Example fix

// before
opacityOp.run(png, [NaN]); // -> Error changing image opacity.
// after
const opacity = Math.max(0, Math.min(100, Number(args[0]) || 0));
opacityOp.run(png, [opacity]);
Defensive patterns

Strategy: validation

Validate before calling

const opacity = Math.max(0, Math.min(100, Number(args[0])));
if (!Number.isFinite(opacity)) throw new Error('opacity must be a number in [0,100]');

Type guard

function isValidOpacity(v) {
  const n = Number(v);
  return Number.isFinite(n) && n >= 0 && n <= 100;
}

Prevention

When it happens

Trigger: opacity arg is NaN (e.g. from empty string), negative, or >100, producing an opacity fraction outside [0,1] that Jimp refuses; or getBuffer fails during PNG encode. Large-image memory pressure can also surface here.

Common situations: Opacity slider cleared or set to a non-number, a corrupted pixel buffer, or an oversized image during encode.

Related errors


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