rotate_image
Rotate images by specified angles to adjust orientation or correct alignment. Specify input/output paths, rotation angle, and background color for exposed areas.
Instructions
Rotate an image by specified degrees
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inputPath | Yes | Path to input image | |
| outputPath | Yes | Path to save rotated image | |
| angle | Yes | Rotation angle in degrees (positive = clockwise) | |
| background | No | Background color for exposed areas (hex or named color) | #000000 |
Implementation Reference
- src/index.ts:321-338 (handler)The handler for the 'rotate_image' tool. It destructures the arguments, ensures the output directory exists, uses Sharp to rotate the image by the specified angle with optional background color, saves it to the output path, and returns a success message.case 'rotate_image': { const { inputPath, outputPath, angle, background = '#000000' } = args; await fs.mkdir(path.dirname(outputPath), { recursive: true }); await sharp(inputPath) .rotate(angle, { background }) .toFile(outputPath); return { content: [ { type: 'text', text: `Image rotated ${angle}° successfully. Saved to: ${outputPath}` } ] }; }
- src/index.ts:120-136 (schema)Input schema for the 'rotate_image' tool defining the expected parameters: inputPath (required), outputPath (required), angle (required number of degrees), and optional background color.inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to input image' }, outputPath: { type: 'string', description: 'Path to save rotated image' }, angle: { type: 'number', description: 'Rotation angle in degrees (positive = clockwise)' }, background: { type: 'string', description: 'Background color for exposed areas (hex or named color)', default: '#000000' } }, required: ['inputPath', 'outputPath', 'angle'] }
- src/index.ts:117-137 (registration)Registration of the 'rotate_image' tool in the ListToolsRequestSchema handler, providing the tool name, description, and input schema.{ name: 'rotate_image', description: 'Rotate an image by specified degrees', inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to input image' }, outputPath: { type: 'string', description: 'Path to save rotated image' }, angle: { type: 'number', description: 'Rotation angle in degrees (positive = clockwise)' }, background: { type: 'string', description: 'Background color for exposed areas (hex or named color)', default: '#000000' } }, required: ['inputPath', 'outputPath', 'angle'] } },