Skip to main content
Glama

batch_resize

Resize a single image to multiple dimensions simultaneously for web optimization, saving each version with custom suffixes in your preferred format.

Instructions

Generate multiple sizes from one image

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
inputPathYesPath to input image
outputDirYesDirectory to save resized images
sizesYesArray of sizes to generate
formatNoOutput format for all sizes

Implementation Reference

  • The handler function for the 'batch_resize' tool. It takes an input image, generates multiple resized versions based on the provided sizes array, optionally converts format, and saves them with suffixes in the output directory.
    case 'batch_resize': { const { inputPath, outputDir, sizes, format } = args; await fs.mkdir(outputDir, { recursive: true }); const basename = path.basename(inputPath, path.extname(inputPath)); const results = []; for (const size of sizes) { const outputName = `${basename}${size.suffix}${format ? `.${format}` : path.extname(inputPath)}`; const outputPath = path.join(outputDir, outputName); let pipeline = sharp(inputPath) .resize({ width: size.width, height: size.height || undefined, fit: 'cover', withoutEnlargement: true }); if (format) { switch (format) { case 'jpeg': case 'jpg': pipeline = pipeline.jpeg({ quality: 80, progressive: true }); break; case 'png': pipeline = pipeline.png(); break; case 'webp': pipeline = pipeline.webp({ quality: 80 }); break; case 'avif': pipeline = pipeline.avif({ quality: 80 }); break; } } await pipeline.toFile(outputPath); results.push(outputPath); } return { content: [ { type: 'text', text: `Batch resize complete. Generated ${results.length} images:\n${results.join('\n')}` } ] }; }
  • The input schema definition for the 'batch_resize' tool, specifying parameters like inputPath, outputDir, sizes array (with width, optional height, suffix), and optional format.
    { name: 'batch_resize', description: 'Generate multiple sizes from one image', inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to input image' }, outputDir: { type: 'string', description: 'Directory to save resized images' }, sizes: { type: 'array', items: { type: 'object', properties: { width: { type: 'number', description: 'Width in pixels' }, height: { type: 'number', description: 'Height in pixels' }, suffix: { type: 'string', description: 'Suffix to add to filename' } }, required: ['width', 'suffix'] }, description: 'Array of sizes to generate' }, format: { type: 'string', enum: ['jpeg', 'jpg', 'png', 'webp', 'avif'], description: 'Output format for all sizes' } }, required: ['inputPath', 'outputDir', 'sizes'] } }
  • src/index.ts:26-197 (registration)
    The ListToolsRequestHandler registration that includes the 'batch_resize' tool in the list of available tools.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { 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'] } }, { name: 'convert_format', description: 'Convert image between formats (jpeg, png, webp, avif)', inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to input image' }, outputPath: { type: 'string', description: 'Path to save converted image' }, format: { type: 'string', enum: ['jpeg', 'jpg', 'png', 'webp', 'avif'], description: 'Target format' }, quality: { type: 'number', minimum: 1, maximum: 100, description: 'Quality for lossy formats (1-100)', default: 80 } }, required: ['inputPath', 'outputPath', 'format'] } }, { 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'] } }, { name: 'compress_image', description: 'Compress an image with quality settings', inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to input image' }, outputPath: { type: 'string', description: 'Path to save compressed image' }, quality: { type: 'number', minimum: 1, maximum: 100, description: 'Compression quality (1-100)', default: 80 }, progressive: { type: 'boolean', description: 'Use progressive encoding (for JPEG)', default: true } }, required: ['inputPath', 'outputPath'] } }, { name: 'rotate_image', description: 'Rotate an image by specified degrees', inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to input image' }, outputPath: { type: 'string', description: 'Path to save rotated image' }, angle: { type: 'number', description: 'Rotation angle in degrees (positive = clockwise)' }, background: { type: 'string', description: 'Background color for exposed areas (hex or named color)', default: '#000000' } }, required: ['inputPath', 'outputPath', 'angle'] } }, { name: 'flip_image', description: 'Flip an image horizontally or vertically', inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to input image' }, outputPath: { type: 'string', description: 'Path to save flipped image' }, direction: { type: 'string', enum: ['horizontal', 'vertical', 'both'], description: 'Flip direction' } }, required: ['inputPath', 'outputPath', 'direction'] } }, { name: 'get_image_info', description: 'Get metadata and information about an image', inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to image file' } }, required: ['inputPath'] } }, { name: 'batch_resize', description: 'Generate multiple sizes from one image', inputSchema: { type: 'object', properties: { inputPath: { type: 'string', description: 'Path to input image' }, outputDir: { type: 'string', description: 'Directory to save resized images' }, sizes: { type: 'array', items: { type: 'object', properties: { width: { type: 'number', description: 'Width in pixels' }, height: { type: 'number', description: 'Height in pixels' }, suffix: { type: 'string', description: 'Suffix to add to filename' } }, required: ['width', 'suffix'] }, description: 'Array of sizes to generate' }, format: { type: 'string', enum: ['jpeg', 'jpg', 'png', 'webp', 'avif'], description: 'Output format for all sizes' } }, required: ['inputPath', 'outputDir', 'sizes'] } } ] }));

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