gchq/CyberChef · error · OperationError

Error rotating image. (${err})

Error message

Error rotating image. (${err})

What it means

Thrown by the catch block wrapping image.rotate(degrees) and getBuffer() in RotateImage.run(). Any failure during rotation or buffer re-encoding is re-wrapped as an OperationError with the underlying message.

Source

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

        try {
            image = await Jimp.read(input);
        } catch (err) {
            throw new OperationError(`Error loading image. (${err})`);
        }
        try {
            if (isWorkerEnvironment())
                self.sendStatusMessage("Rotating image...");
            image.rotate(degrees);

            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 rotating image. (${err})`);
        }
    }

    /**
     * Displays the rotated 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. Read the embedded 'err' to distinguish a rotation failure from a getBuffer encoding failure.
  2. Ensure degrees is a finite number (the UI default is 90).
  3. Convert GIF input to PNG before rotating if the re-encode is the problem.
  4. Verify the Jimp version matches what the operation targets.
Defensive patterns

Strategy: try-catch

Validate before calling

if (typeof degrees !== "number" || !Number.isFinite(degrees)) {
  throw new Error("degrees must be a finite number");
}

Type guard

function isValidDegrees(d) { return typeof d === "number" && Number.isFinite(d); }

Try / catch

try {
  image.rotate(degrees);
} catch (err) {
  throw new OperationError(`Error rotating image. (${err})`);
}

Prevention

When it happens

Trigger: Jimp.rotate() failing on certain degrees values, or getBuffer() failing to encode the rotated result. GIF inputs are re-encoded as PNG, which can fail for animated/multi-frame GIFs.

Common situations: Passing a non-numeric or NaN degrees value through the API; rotating an animated GIF that cannot be flattened to PNG; a corrupted image that decoded but cannot be re-encoded; Jimp version incompatibility.

Related errors


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