resize_image
Resize images to specific dimensions with control over width, height, and aspect ratio using the Imagician server's image editing capabilities.
Instructions
Resize an image to specified dimensions
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inputPath | Yes | Path to input image | |
| outputPath | Yes | Path to save resized image | |
| width | No | Target width in pixels | |
| height | No | Target height in pixels | |
| fit | No | How the image should be resized to fit | cover |
| preserveAspectRatio | No | Maintain original aspect ratio |
Implementation Reference
- src/index.ts:204-230 (handler)The handler function for the 'resize_image' tool. It destructures the input arguments, ensures the output directory exists, creates a Sharp pipeline for the input image, applies resize operation if width or height specified, and saves the result to outputPath. Returns a success message.
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}` } ] }; } - src/index.ts:29-52 (registration)The tool registration in the ListTools response, including name, description, and inputSchema defining parameters for input/output paths, dimensions, fit mode, and aspect ratio preservation.
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'] } }, - src/index.ts:31-50 (schema)The input schema for the resize_image tool, specifying the object structure, properties with types and descriptions, required fields, and defaults.
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']