Skip to main content
Glama

resize_image

Resize image files to specified height and width using methods like fit, scale, cover, or thumb. Save output to a designated path for efficient image processing.

Instructions

Resize an image file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
heightYesThe height to resize the image to
imagePathYesThe ABSOLUTE path to the image file to resize
methodNoThe method describes the way your image will be resized.fit
outputPathNoThe ABSOLUTE path to save the resized image file
widthYesThe width to resize the image to

Implementation Reference

  • MCP tool handler for 'resize_image' that invokes the resize logic and returns a success response.
    resize_image: async (request) => { await handleResizeImageTool( request.params.arguments as { imagePath: string; outputPath?: string; width: number; height: number; method: 'scale' | 'fit' | 'cover' | 'thumb'; }, ); return { content: [ { type: 'text', text: 'Image resized successfully', }, ], metadata: {}, }; },
  • Tool schema definition for 'resize_image', including input schema with properties for image path, dimensions, resize method, and output path.
    const RESIZE_IMAGE_TOOL: Tool = { name: 'resize_image', description: 'Resize an image file', inputSchema: { type: 'object', properties: { imagePath: { type: 'string', description: 'The ABSOLUTE path to the image file to resize', example: '/Users/user/Downloads/image.jpg', }, outputPath: { type: 'string', description: 'The ABSOLUTE path to save the resized image file', example: '/Users/user/Downloads/image_thumbnail.jpg', }, method: { type: 'string', description: 'The method describes the way your image will be resized.', enum: ['scale', 'fit', 'cover', 'thumb'], default: 'fit', example: 'fit', }, width: { type: 'number', description: 'The width to resize the image to', example: 1024, }, height: { type: 'number', description: 'The height to resize the image to', example: 1024, }, }, required: ['imagePath', 'width', 'height'], }, };
  • src/tools.ts:117-117 (registration)
    Registration of the 'resize_image' tool in the exported TOOLS array for MCP tool discovery.
    export const TOOLS = [COMPRESS_LOCAL_IMAGE_TOOL, COMPRESS_REMOTE_IMAGE_TOOL, RESIZE_IMAGE_TOOL];
  • Helper function implementing the core resize logic using the tinify library to resize the image to specified dimensions.
    async function handleResizeImageTool({ imagePath, outputPath, width, height, method, }: { imagePath: string; outputPath?: string; width: number; height: number; method?: 'scale' | 'fit' | 'cover' | 'thumb'; }) { const source = tinify.fromFile(imagePath); const resized = source.resize({ method: method || 'fit', width, height, }); let dest = outputPath; if (!dest) { const dir = path.dirname(imagePath); const basename = path.basename(imagePath, path.extname(imagePath)); const ext = path.extname(imagePath).slice(1); dest = path.join(dir, `${basename}_${width}x${height}.${ext}`); } await resized.toFile(dest); }

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/zhendi/tinypng-mcp-server'

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