Skip to main content
Glama

rotation-info

Extract rotation and flip orientation data from images to analyze and correct image alignment issues using EXIF metadata.

Instructions

Get detailed rotation and flip information from image orientation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
imageYes

Implementation Reference

  • The main handler function that loads the image buffer using loadImage and retrieves rotation/flip info using exifr.rotation.
    async (args, extra) => { try { const { image } = args; const buf = await loadImage(image); const rotation = await exifr.rotation(buf); if (!rotation) { return createErrorResponse('No rotation metadata found in image'); } return createSuccessResponse(rotation); } catch (error) { return createErrorResponse(`Error reading rotation info: ${error instanceof Error ? error.message : String(error)}`); } }
  • Registers the 'rotation-info' tool on the MCP server with name, description, input schema, and handler function.
    // Tool 9: rotation-info - gets rotation and flip information const rotationInfoTool = server.tool('rotation-info', "Get detailed rotation and flip information from image orientation", { image: ImageSourceSchema }, async (args, extra) => { try { const { image } = args; const buf = await loadImage(image); const rotation = await exifr.rotation(buf); if (!rotation) { return createErrorResponse('No rotation metadata found in image'); } return createSuccessResponse(rotation); } catch (error) { return createErrorResponse(`Error reading rotation info: ${error instanceof Error ? error.message : String(error)}`); } } ); tools['rotation-info'] = rotationInfoTool;
  • Zod schema defining the input 'image' parameter as ImageSource (path, url, base64, or buffer).
    const ImageSourceSchema = z.object({ kind: z.enum(['path', 'url', 'base64', 'buffer']), path: z.string().optional(), url: z.string().optional(), data: z.string().optional(), buffer: z.string().optional() });
  • Helper function to load image data into buffer from various source types, used in the handler.
    export async function loadImage(src: ImageSourceType): Promise<Buffer | Uint8Array> { try { switch (src.kind) { case 'path': if (!src.path) { throw new Error('Path is required for kind="path"'); } return await fs.promises.readFile(src.path); case 'url': if (!src.url) { throw new Error('URL is required for kind="url"'); } if (src.url.startsWith('file://')) { // Handle file:// URLs by converting to filesystem path const filePath = fileURLToPath(src.url); return await fs.promises.readFile(filePath); } else { // Handle HTTP/HTTPS URLs const response = await fetch(src.url); if (!response.ok) { throw new Error(`Failed to fetch URL: ${response.status} ${response.statusText}`); } return new Uint8Array(await response.arrayBuffer()); } case 'base64': if (!src.data) { throw new Error('Data is required for kind="base64"'); } // Check for potential oversized base64 string (>30MB) if (src.data.length > 40000000) { // ~30MB in base64 throw new Error('PayloadTooLarge: Base64 data exceeds 30MB limit'); } // Handle data URIs or raw base64 if (src.data.startsWith('data:')) { const base64Data = src.data.split(',')[1]; return Buffer.from(base64Data, 'base64'); } else { return Buffer.from(src.data, 'base64'); } case 'buffer': if (!src.buffer) { throw new Error('Buffer is required for kind="buffer"'); } return Buffer.from(src.buffer, 'base64'); default: // This should never happen due to type constraints, but TypeScript needs it throw new Error(`Unsupported image source kind: ${(src as any).kind}`); } } catch (error) { if (error instanceof Error) { throw new Error(`Failed to load image: ${error.message}`); } throw error; } }

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/stass/exif-mcp'

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