Skip to main content
Glama

resize_image

Resize images to custom dimensions or named presets while preserving the original format and aspect ratio.

Instructions

Resize an image to custom dimensions or a named preset. Preserves the original format.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
input_pathYesAbsolute path to the source image file
widthNoTarget width in pixels
heightNoTarget height in pixels
presetNoNamed size preset (overrides width/height)
lock_aspect_ratioNoKeep aspect ratio (default true)
output_pathNoWhere to save the output (defaults to same directory as input)

Implementation Reference

  • The "resize_image" tool is registered and implemented in index.js. It uses the 'sharp' library to resize images based on provided dimensions or presets.
    server.tool(
      "resize_image",
      "Resize an image to custom dimensions or a named preset. Preserves the original format.",
      {
        input_path: z.string().describe("Absolute path to the source image file"),
        width: z.number().int().positive().optional().describe("Target width in pixels"),
        height: z.number().int().positive().optional().describe("Target height in pixels"),
        preset: z.enum([
          "instagram-square", "instagram-portrait", "instagram-landscape",
          "twitter-post", "twitter-header", "full-hd", "4k",
          "youtube-thumbnail", "favicon",
        ]).optional().describe("Named size preset (overrides width/height)"),
        lock_aspect_ratio: z.boolean().optional().default(true).describe("Keep aspect ratio (default true)"),
        output_path: z.string().optional().describe("Where to save the output (defaults to same directory as input)"),
      },
      async ({ input_path, width, height, preset, lock_aspect_ratio = true, output_path }) => {
        try {
          await fs.access(input_path);
          let targetW = width;
          let targetH = height;
          if (preset) {
            targetW = PRESETS[preset].width;
            targetH = PRESETS[preset].height;
          }
          if (!targetW && !targetH) {
            return { isError: true, content: [{ type: "text", text: "Provide width, height, or a preset." }] };
          }
          const ext = path.extname(input_path).slice(1).toLowerCase() || "jpg";
          const outPath = resolveOutputPath(input_path, ext, output_path);
          const fit = lock_aspect_ratio ? "inside" : "fill";
          await sharp(input_path).resize(targetW, targetH, { fit }).toFile(outPath);
          const stat = await fs.stat(outPath);
          const meta = await sharp(outPath).metadata();
          return {
            content: [{ type: "text", text: JSON.stringify({ success: true, output_path: outPath, width: meta.width, height: meta.height, size_bytes: stat.size }) }],
          };
        } catch (err) {
          return { isError: true, content: [{ type: "text", text: `Error: ${err.message}` }] };
        }
      }
    );
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions that the tool 'preserves the original format', which is a useful behavioral trait, but fails to describe other critical aspects such as whether it modifies the original file, handles errors, supports specific image formats, or has performance implications. For a mutation tool with zero annotation coverage, this leaves significant gaps.

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 front-loads the core functionality ('resize an image') and includes a key behavioral note ('preserves the original format'). There is zero waste, and every word earns its place by adding value beyond the schema.

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

Completeness3/5

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

Given the tool's moderate complexity (6 parameters, mutation operation) and lack of annotations or output schema, the description is incomplete. It covers the basic purpose and format preservation but omits details on error handling, supported inputs, output behavior, and performance. It's adequate as a minimum viable description but has clear gaps for effective agent use.

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 minimal value beyond the schema by hinting at the 'preset' parameter's purpose ('named preset'), but doesn't provide additional syntax, format details, or usage examples. Baseline 3 is appropriate when the schema does the heavy lifting.

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

Purpose5/5

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

The description clearly states the tool's purpose with specific verbs ('resize') and resources ('image'), and distinguishes it from siblings by specifying it preserves the original format, unlike 'convert_and_resize' or 'convert_image' which likely change formats. It explicitly mentions both custom dimensions and named presets.

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

Usage Guidelines3/5

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

The description implies usage by mentioning 'custom dimensions or a named preset', but provides no explicit guidance on when to use this tool versus alternatives like 'convert_and_resize' or 'process_folder'. It doesn't specify prerequisites or exclusions, leaving the agent to infer context from sibling names alone.

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/sonic0002/imagic-mcp'

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