Skip to main content
Glama

resize_image

Adjust image dimensions precisely by specifying width, height, and fit options. Maintain aspect ratio or customize fit for desired output. Save resized images in supported formats.

Instructions

Resize an image to specified dimensions

Input Schema

NameRequiredDescriptionDefault
fitNoHow the image should be resized to fitcover
heightNoTarget height in pixels
inputPathYesPath to input image
outputPathYesPath to save resized image
preserveAspectRatioNoMaintain original aspect ratio
widthNoTarget width in pixels

Input Schema (JSON Schema)

{ "properties": { "fit": { "default": "cover", "description": "How the image should be resized to fit", "enum": [ "cover", "contain", "fill", "inside", "outside" ], "type": "string" }, "height": { "description": "Target height in pixels", "type": "number" }, "inputPath": { "description": "Path to input image", "type": "string" }, "outputPath": { "description": "Path to save resized image", "type": "string" }, "preserveAspectRatio": { "default": true, "description": "Maintain original aspect ratio", "type": "boolean" }, "width": { "description": "Target width in pixels", "type": "number" } }, "required": [ "inputPath", "outputPath" ], "type": "object" }

Implementation Reference

  • The main execution logic for the resize_image tool, using Sharp to create a resize pipeline and save the output image.
    case 'resize_image': { const { inputPath, outputPath, width, height, fit = 'cover', preserveAspectRatio = true } = args; await fs.mkdir(path.dirname(outputPath), { recursive: true }); let pipeline = sharp(inputPath); if (width || height) { pipeline = pipeline.resize({ width: width || undefined, height: height || undefined, fit: fit as any, withoutEnlargement: preserveAspectRatio }); } await pipeline.toFile(outputPath); return { content: [ { type: 'text', text: `Image resized successfully. Saved to: ${outputPath}` } ] }; }
  • Input schema defining the parameters for the resize_image tool, including paths, dimensions, fit mode, and aspect ratio preservation.
    inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to input image' }, outputPath: { type: 'string', description: 'Path to save resized image' }, width: { type: 'number', description: 'Target width in pixels' }, height: { type: 'number', description: 'Target height in pixels' }, fit: { type: 'string', enum: ['cover', 'contain', 'fill', 'inside', 'outside'], description: 'How the image should be resized to fit', default: 'cover' }, preserveAspectRatio: { type: 'boolean', description: 'Maintain original aspect ratio', default: true } }, required: ['inputPath', 'outputPath'] }
  • src/index.ts:28-52 (registration)
    Registration of the resize_image tool within the ListToolsRequestSchema response, including name, description, and input schema.
    { name: 'resize_image', description: 'Resize an image to specified dimensions', inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to input image' }, outputPath: { type: 'string', description: 'Path to save resized image' }, width: { type: 'number', description: 'Target width in pixels' }, height: { type: 'number', description: 'Target height in pixels' }, fit: { type: 'string', enum: ['cover', 'contain', 'fill', 'inside', 'outside'], description: 'How the image should be resized to fit', default: 'cover' }, preserveAspectRatio: { type: 'boolean', description: 'Maintain original aspect ratio', default: true } }, required: ['inputPath', 'outputPath'] } },

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/flowy11/imagician'

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