Skip to main content
Glama

batch_resize

Resize one image into multiple dimensions simultaneously. Specify custom widths, heights, and suffixes for each output. Save resized versions in JPEG, PNG, WebP, or AVIF formats efficiently.

Instructions

Generate multiple sizes from one image

Input Schema

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

Implementation Reference

  • The batch_resize tool handler that processes the request by creating an output directory, extracting the base filename, iterating over the sizes array, resizing each image using Sharp with 'cover' fit and without enlargement, optionally converting to the specified format, saving each to the output directory with a suffix, and returning a success message with the list of generated files.
    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 tool registration block defining the name, description, and input schema (including properties for inputPath, outputDir, sizes array with width/suffix/optional height, and optional format) for the batch_resize tool.
    { 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'] } }

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/flowy11/imagician'

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