resize_image
Resize images to specific dimensions using scale, fit, cover, or thumb methods for web optimization and display requirements.
Instructions
Resize an image file
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"imagePath": "<imagePath>",
"width": "<width>",
"height": "<height>"
},
"name": "resize_image"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| imagePath | Yes | The ABSOLUTE path to the image file to resize | |
| outputPath | No | The ABSOLUTE path to save the resized image file | |
| method | No | The method describes the way your image will be resized. | fit |
| width | Yes | The width to resize the image to | |
| height | Yes | The height to resize the image to |
Implementation Reference
- src/tools.ts:280-299 (handler)Handler function for 'resize_image' tool in TOOL_HANDLERS, which extracts parameters and calls the core resize logic.
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: {}, }; }, - src/tools.ts:213-241 (helper)Core implementation of image resizing using Tinify API, handling input parameters, resizing, and output path generation.
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); } - src/tools.ts:79-115 (schema)Tool definition including name, description, and input schema for 'resize_image'.
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.
export const TOOLS = [COMPRESS_LOCAL_IMAGE_TOOL, COMPRESS_REMOTE_IMAGE_TOOL, RESIZE_IMAGE_TOOL];