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']
          }
        }
      ]
    }));
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. 'Generate multiple sizes' implies a write/mutation operation, but it doesn't specify whether this overwrites existing files, requires specific permissions, has rate limits, or what happens on failure. For a tool that creates multiple output files, this lack of behavioral context is a significant gap.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that immediately conveys the core functionality. There's zero wasted language or unnecessary elaboration. It's appropriately sized for the tool's complexity and gets straight to the point.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with 4 parameters, no annotations, and no output schema, the description is inadequate. It doesn't explain what the tool returns, how errors are handled, or the behavioral implications of generating multiple files. Given the complexity and lack of structured metadata, the description should provide more operational context to be complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters thoroughly. The description adds no additional parameter information beyond what's in the schema - it doesn't explain relationships between parameters or provide usage examples. This meets the baseline for high schema coverage but doesn't add extra value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Generate multiple sizes from one image' clearly states the verb ('generate') and resource ('multiple sizes from one image'), making the purpose immediately understandable. It distinguishes from siblings like 'resize_image' by specifying batch/multiple operations, though it doesn't explicitly contrast with all alternatives like 'compress_image' or 'crop_image'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention scenarios where batch resizing is preferred over single resizing ('resize_image'), or when other tools like 'compress_image' or 'convert_format' might be more appropriate. There's no context about prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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