{"record":{"id":"ef36b15ff608efae","repo":"gchq/CyberChef","slug":"error-rotating-image-err","errorCode":null,"errorMessage":"Error rotating image. (${err})","messagePattern":"Error rotating image\\. \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/RotateImage.mjs","lineNumber":72,"sourceCode":"        try {\n            image = await Jimp.read(input);\n        } catch (err) {\n            throw new OperationError(`Error loading image. (${err})`);\n        }\n        try {\n            if (isWorkerEnvironment())\n                self.sendStatusMessage(\"Rotating image...\");\n            image.rotate(degrees);\n\n            let imageBuffer;\n            if (image.mime === \"image/gif\") {\n                imageBuffer = await image.getBuffer(JimpMime.png);\n            } else {\n                imageBuffer = await image.getBuffer(image.mime);\n            }\n            return imageBuffer.buffer;\n        } catch (err) {\n            throw new OperationError(`Error rotating image. (${err})`);\n        }\n    }\n\n    /**\n     * Displays the rotated image using HTML for web apps\n     * @param {ArrayBuffer} data\n     * @returns {html}\n     */\n    present(data) {\n        if (!data.byteLength) return \"\";\n        const dataArray = new Uint8Array(data);\n\n        const type = isImage(dataArray);\n        if (!type) {\n            throw new OperationError(\"Invalid file type.\");\n        }\n\n        return `<img src=\"data:${type};base64,${toBase64(dataArray)}\">`;","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/RotateImage.mjs#L54-L90","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the embedded 'err' to distinguish a rotation failure from a getBuffer encoding failure.","Ensure degrees is a finite number (the UI default is 90).","Convert GIF input to PNG before rotating if the re-encode is the problem.","Verify the Jimp version matches what the operation targets."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if (typeof degrees !== \"number\" || !Number.isFinite(degrees)) {\n  throw new Error(\"degrees must be a finite number\");\n}","typeGuard":"function isValidDegrees(d) { return typeof d === \"number\" && Number.isFinite(d); }","tryCatchPattern":"try {\n  image.rotate(degrees);\n} catch (err) {\n  throw new OperationError(`Error rotating image. (${err})`);\n}","preventionTips":["Ensure degrees is a finite number (default 90).","Convert GIFs to PNG before rotating if the re-encode fails."],"tags":["image","jimp","rotation","operation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}