Skip to main content
Glama

rotate-image

Rotate an image by a specified angle in degrees using the MCP Media Processing Server. Input the image path and rotation angle, and optionally set an output path or filename for the rotated image.

Instructions

Rotate image by specified degrees

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
degreesYesRotation angle in degrees
inputPathYesAbsolute path to input image file
outputFilenameNoOutput filename (only used if outputPath is not provided)
outputPathNoOptional absolute path for output file. If not provided, file will be saved in Downloads folder

Implementation Reference

  • Executes image rotation using ImageMagick 'convert' command with -rotate option. Handles path resolution, output path generation, command execution, and error handling.
    async ({ inputPath, degrees, outputPath, outputFilename }) => { try { await checkImageMagick(); const absoluteInputPath = await getAbsolutePath(inputPath); const inputFileName = absoluteInputPath.split('/').pop()?.split('.')[0] || 'output'; const extension = absoluteInputPath.split('.').pop() || 'png'; const defaultFilename = outputFilename || `${inputFileName}_rotated.${extension}`; const finalOutputPath = await getOutputPath(outputPath, defaultFilename); const command = `convert "${absoluteInputPath}" -rotate ${degrees} "${finalOutputPath}"`; await execSync(command); return { content: [ { type: "text", text: `Image successfully rotated and saved to: ${finalOutputPath}`, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error rotating image: ${errorMessage}`, }, ], }; } }
  • Zod schema defining input parameters for the rotate-image tool: inputPath, degrees, optional outputPath and outputFilename.
    { inputPath: z.string().describe("Absolute path to input image file"), degrees: z.number().describe("Rotation angle in degrees"), outputPath: z.string().optional().describe("Optional absolute path for output file. If not provided, file will be saved in Downloads folder"), outputFilename: z.string().optional().describe("Output filename (only used if outputPath is not provided)") },
  • src/index.ts:421-462 (registration)
    Registers the 'rotate-image' tool with the MCP server, providing name, description, input schema, and handler function.
    server.tool( "rotate-image", "Rotate image by specified degrees", { inputPath: z.string().describe("Absolute path to input image file"), degrees: z.number().describe("Rotation angle in degrees"), outputPath: z.string().optional().describe("Optional absolute path for output file. If not provided, file will be saved in Downloads folder"), outputFilename: z.string().optional().describe("Output filename (only used if outputPath is not provided)") }, async ({ inputPath, degrees, outputPath, outputFilename }) => { try { await checkImageMagick(); const absoluteInputPath = await getAbsolutePath(inputPath); const inputFileName = absoluteInputPath.split('/').pop()?.split('.')[0] || 'output'; const extension = absoluteInputPath.split('.').pop() || 'png'; const defaultFilename = outputFilename || `${inputFileName}_rotated.${extension}`; const finalOutputPath = await getOutputPath(outputPath, defaultFilename); const command = `convert "${absoluteInputPath}" -rotate ${degrees} "${finalOutputPath}"`; await execSync(command); return { content: [ { type: "text", text: `Image successfully rotated and saved to: ${finalOutputPath}`, }, ], }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [ { type: "text", text: `Error rotating image: ${errorMessage}`, }, ], }; } } );
  • Helper function to verify ImageMagick installation by executing 'convert -version'.
    async function checkImageMagick() { try { execSync('convert -version'); return true; } catch (error) { throw new Error('ImageMagick is not installed. Please install it first.'); } }
  • Helper to resolve relative input paths to absolute paths using process.cwd() and verify file accessibility.
    async function getAbsolutePath(inputPath: string): Promise<string> { if (isAbsolute(inputPath)) { return inputPath; } // FIXME: But it's not working, because the server is running in a different directory const absolutePath = resolve(process.cwd(), inputPath); try { await fs.access(absolutePath); return absolutePath; } catch (error) { throw new Error(`Input file not found: ${inputPath}`); } }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/maoxiaoke/mcp-media-processor'

If you have feedback or need assistance with the MCP directory API, please join our Discord server