Skip to main content
Glama

resize_image

Adjust image dimensions by specifying width, height, and fit method. Save the resized image to a designated path for optimized file management.

Instructions

Resize an image and save to a new file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fitNoFit method: cover, contain, fill, inside, outside
heightNoTarget height in pixels (optional)
inputYesPath to the input image file
outputYesPath to save the resized image
widthYesTarget width in pixels

Implementation Reference

  • Executes the resize_image tool: validates input, uses Sharp to resize the image to specified dimensions with fit option, saves to output path, retrieves metadata, and returns success message or error.
    case "resize_image": { const { input, output, width, height, fit = "cover" } = request.params.arguments as { input: string, output: string, width: number, height?: number, fit?: string }; if (!input || !output || !width) { throw new McpError(ErrorCode.InvalidParams, "Input path, output path, and width are required"); } if (!fs.existsSync(input)) { throw new McpError(ErrorCode.InvalidRequest, `Input image not found: ${input}`); } try { // Create output directory if it doesn't exist await fsExtra.ensureDir(path.dirname(output)); // Resize the image await sharp(input) .resize({ width, height, fit: fit as keyof sharp.FitEnum }) .toFile(output); // Get metadata of the resized image const metadata = await getImageMetadata(output); return { content: [ { type: "text", text: `Image resized successfully:\n` + `- Original: ${input}\n` + `- Resized: ${output}\n` + `- New dimensions: ${metadata.width}x${metadata.height}\n` + `- Size: ${(metadata.size / 1024).toFixed(2)} KB` } ] }; } catch (error) { return { content: [ { type: "text", text: `Error resizing image: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } }
  • Input schema defining parameters for resize_image: input/output paths, width (required), optional height and fit method.
    inputSchema: { type: "object", properties: { input: { type: "string", description: "Path to the input image file" }, output: { type: "string", description: "Path to save the resized image" }, width: { type: "number", description: "Target width in pixels" }, height: { type: "number", description: "Target height in pixels (optional)" }, fit: { type: "string", description: "Fit method: cover, contain, fill, inside, outside", enum: ["cover", "contain", "fill", "inside", "outside"] } }, required: ["input", "output", "width"] }
  • src/index.ts:251-281 (registration)
    Tool registration in the server.setTools array, including name, description, and input schema.
    { name: "resize_image", description: "Resize an image and save to a new file", inputSchema: { type: "object", properties: { input: { type: "string", description: "Path to the input image file" }, output: { type: "string", description: "Path to save the resized image" }, width: { type: "number", description: "Target width in pixels" }, height: { type: "number", description: "Target height in pixels (optional)" }, fit: { type: "string", description: "Fit method: cover, contain, fill, inside, outside", enum: ["cover", "contain", "fill", "inside", "outside"] } }, required: ["input", "output", "width"] } },

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/rupeedev/mcp-image-reader'

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