crop_image
Crop images to specific dimensions by defining pixel coordinates for left, top, width, and height parameters within the Imagician server's editing toolkit.
Instructions
Crop an image to specified region
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inputPath | Yes | Path to input image | |
| outputPath | Yes | Path to save cropped image | |
| left | Yes | Left offset in pixels | |
| top | Yes | Top offset in pixels | |
| width | Yes | Width of crop area | |
| height | Yes | Height of crop area |
Implementation Reference
- src/index.ts:267-284 (handler)Handler for 'crop_image' tool: destructures args, ensures output dir, uses sharp.extract() to crop the image region specified by left, top, width, height, saves to outputPath, returns success message.case 'crop_image': { const { inputPath, outputPath, left, top, width, height } = args; await fs.mkdir(path.dirname(outputPath), { recursive: true }); await sharp(inputPath) .extract({ left, top, width, height }) .toFile(outputPath); return { content: [ { type: 'text', text: `Image cropped successfully. Saved to: ${outputPath}` } ] }; }
- src/index.ts:78-92 (schema)Schema definition for 'crop_image' tool in ListTools response, including inputSchema with properties for image paths and crop parameters (left, top, width, height), all required.name: 'crop_image', description: 'Crop an image to specified region', inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to input image' }, outputPath: { type: 'string', description: 'Path to save cropped image' }, left: { type: 'number', description: 'Left offset in pixels' }, top: { type: 'number', description: 'Top offset in pixels' }, width: { type: 'number', description: 'Width of crop area' }, height: { type: 'number', description: 'Height of crop area' } }, required: ['inputPath', 'outputPath', 'left', 'top', 'width', 'height'] } },
- src/index.ts:78-92 (registration)Registration of 'crop_image' tool in the tools list returned by ListToolsRequestHandler.name: 'crop_image', description: 'Crop an image to specified region', inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to input image' }, outputPath: { type: 'string', description: 'Path to save cropped image' }, left: { type: 'number', description: 'Left offset in pixels' }, top: { type: 'number', description: 'Top offset in pixels' }, width: { type: 'number', description: 'Width of crop area' }, height: { type: 'number', description: 'Height of crop area' } }, required: ['inputPath', 'outputPath', 'left', 'top', 'width', 'height'] } },