Skip to main content
Glama

resize_image

Resize and reformat images for social media platforms using AI outpainting to intelligently extend content for new aspect ratios.

Instructions

Resize/reformat images for different platforms (like Canva Magic Resize). Uses AI outpainting to intelligently extend content for new aspect ratios. Note: 'crop' and 'letterbox' modes coming soon.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_urlYesURL of the source image (use upload_file for local images)
target_formatYesTarget platform format, or 'custom' to specify dimensions
widthNoCustom width in pixels (required if target_format='custom')
heightNoCustom height in pixels (required if target_format='custom')
modeNoHow to handle aspect ratio change: extend (AI outpainting - recommended), crop (coming soon), letterbox (coming soon)extend
background_promptNoFor 'extend' mode: prompt to guide AI-generated extended areas (e.g., 'continue the beach scenery')
background_colorNoFor 'letterbox' mode: hex color for bars (e.g., '#FFFFFF' for white)#000000

Implementation Reference

  • Main execution logic for the resize_image tool. Parses arguments, validates format/mode, determines target dimensions using SOCIAL_MEDIA_FORMATS, and routes to mode-specific helpers (extend via AI outpainting, placeholders for crop/letterbox).
    async def handle_resize_image(
        arguments: Dict[str, Any],
        registry: ModelRegistry,
        queue_strategy: QueueStrategy,
    ) -> List[TextContent]:
        """Handle the resize_image tool for Canva-style image resizing."""
        target_format = arguments["target_format"]
        mode = arguments.get("mode", "extend")
    
        # Determine target dimensions
        if target_format == "custom":
            if "width" not in arguments or "height" not in arguments:
                return [
                    TextContent(
                        type="text",
                        text="❌ Custom format requires both 'width' and 'height' parameters.",
                    )
                ]
            target_width = arguments["width"]
            target_height = arguments["height"]
            format_label = f"custom ({target_width}x{target_height})"
        else:
            if target_format not in SOCIAL_MEDIA_FORMATS:
                return [
                    TextContent(
                        type="text",
                        text=f"❌ Unknown format: {target_format}. Available formats: {', '.join(SOCIAL_MEDIA_FORMATS.keys())}",
                    )
                ]
            format_info = SOCIAL_MEDIA_FORMATS[target_format]
            target_width = format_info["width"]
            target_height = format_info["height"]
            format_label = f"{target_format} ({target_width}x{target_height})"
    
        logger.info(
            "Resizing image to %s using mode=%s",
            format_label,
            mode,
        )
    
        if mode == "extend":
            # Use AI outpainting to extend the image
            return await _resize_with_outpainting(
                arguments,
                target_width,
                target_height,
                format_label,
                registry,
                queue_strategy,
            )
        elif mode == "crop":
            # Smart crop to target dimensions
            return await _resize_with_crop(
                arguments,
                target_width,
                target_height,
                format_label,
                registry,
                queue_strategy,
            )
        elif mode == "letterbox":
            # Add letterbox bars
            return await _resize_with_letterbox(
                arguments,
                target_width,
                target_height,
                format_label,
                registry,
                queue_strategy,
            )
        else:
            return [
                TextContent(
                    type="text",
                    text=f"❌ Unknown resize mode: {mode}. Use 'extend', 'crop', or 'letterbox'.",
                )
            ]
  • JSON schema definition for the resize_image tool, including social media presets, custom dimensions, resize modes, and supporting parameters.
    Tool(
        name="resize_image",
        description="Resize/reformat images for different platforms (like Canva Magic Resize). Uses AI outpainting to intelligently extend content for new aspect ratios. Note: 'crop' and 'letterbox' modes coming soon.",
        inputSchema={
            "type": "object",
            "properties": {
                "image_url": {
                    "type": "string",
                    "description": "URL of the source image (use upload_file for local images)",
                },
                "target_format": {
                    "type": "string",
                    "enum": [
                        "instagram_post",
                        "instagram_story",
                        "instagram_reel",
                        "youtube_thumbnail",
                        "youtube_short",
                        "twitter_post",
                        "twitter_header",
                        "linkedin_post",
                        "linkedin_banner",
                        "facebook_post",
                        "facebook_cover",
                        "pinterest_pin",
                        "tiktok",
                        "custom",
                    ],
                    "description": "Target platform format, or 'custom' to specify dimensions",
                },
                "width": {
                    "type": "integer",
                    "minimum": 64,
                    "maximum": 4096,
                    "description": "Custom width in pixels (required if target_format='custom')",
                },
                "height": {
                    "type": "integer",
                    "minimum": 64,
                    "maximum": 4096,
                    "description": "Custom height in pixels (required if target_format='custom')",
                },
                "mode": {
                    "type": "string",
                    "enum": ["extend", "crop", "letterbox"],
                    "default": "extend",
                    "description": "How to handle aspect ratio change: extend (AI outpainting - recommended), crop (coming soon), letterbox (coming soon)",
                },
                "background_prompt": {
                    "type": "string",
                    "description": "For 'extend' mode: prompt to guide AI-generated extended areas (e.g., 'continue the beach scenery')",
                },
                "background_color": {
                    "type": "string",
                    "default": "#000000",
                    "description": "For 'letterbox' mode: hex color for bars (e.g., '#FFFFFF' for white)",
                },
            },
            "required": ["image_url", "target_format"],
        },
    ),
  • Registration of the resize_image handler in the central TOOL_HANDLERS dictionary used by the MCP server's call_tool method to route tool calls.
    TOOL_HANDLERS = {
        # Utility tools (no queue needed)
        "list_models": handle_list_models,
        "recommend_model": handle_recommend_model,
        "get_pricing": handle_get_pricing,
        "get_usage": handle_get_usage,
        "upload_file": handle_upload_file,
        # Image generation tools
        "generate_image": handle_generate_image,
        "generate_image_structured": handle_generate_image_structured,
        "generate_image_from_image": handle_generate_image_from_image,
        # Image editing tools
        "remove_background": handle_remove_background,
        "upscale_image": handle_upscale_image,
        "edit_image": handle_edit_image,
        "inpaint_image": handle_inpaint_image,
        "resize_image": handle_resize_image,
        "compose_images": handle_compose_images,
        # Video tools
        "generate_video": handle_generate_video,
        "generate_video_from_image": handle_generate_video_from_image,
        "generate_video_from_video": handle_generate_video_from_video,
        # Audio tools
        "generate_music": handle_generate_music,
    }
  • Preset dimensions for social media formats used by the resize_image handler to map target_format strings to width/height.
    SOCIAL_MEDIA_FORMATS = {
        "instagram_post": {"width": 1080, "height": 1080, "aspect": "1:1"},
        "instagram_story": {"width": 1080, "height": 1920, "aspect": "9:16"},
        "instagram_reel": {"width": 1080, "height": 1920, "aspect": "9:16"},
        "youtube_thumbnail": {"width": 1280, "height": 720, "aspect": "16:9"},
        "youtube_short": {"width": 1080, "height": 1920, "aspect": "9:16"},
        "twitter_post": {"width": 1200, "height": 675, "aspect": "16:9"},
        "twitter_header": {"width": 1500, "height": 500, "aspect": "3:1"},
        "linkedin_post": {"width": 1200, "height": 627, "aspect": "1.91:1"},
        "linkedin_banner": {"width": 1584, "height": 396, "aspect": "4:1"},
        "facebook_post": {"width": 1200, "height": 630, "aspect": "1.91:1"},
        "facebook_cover": {"width": 820, "height": 312, "aspect": "2.63:1"},
        "pinterest_pin": {"width": 1000, "height": 1500, "aspect": "2:3"},
        "tiktok": {"width": 1080, "height": 1920, "aspect": "9:16"},
    }
  • Export of the handle_resize_image function from image_editing_handlers for use in server.py.
    handle_resize_image,
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses key behavioral traits: it uses 'AI outpainting to intelligently extend content' (implying content generation beyond simple scaling) and notes that some modes are 'coming soon' (managing expectations). However, it doesn't mention critical aspects like rate limits, authentication needs, file size limits, processing time, or what happens to image quality. For a tool with AI generation capabilities, this 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.

Conciseness4/5

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

The description is appropriately concise with three sentences that each serve a purpose: stating the core function, explaining the AI method, and noting upcoming features. It's front-loaded with the main purpose. The only minor inefficiency is the parenthetical '(like Canva Magic Resize)' which, while helpful for context, could be considered slightly extraneous.

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 complexity (AI-powered image transformation with 7 parameters), no annotations, and no output schema, the description is moderately complete. It covers the core functionality and AI method but lacks important contextual information: what the output looks like (URL? file? format?), error conditions, performance characteristics, or integration notes with sibling tools like 'upload_file'. The mention of 'coming soon' features helps manage expectations but doesn't fully compensate for missing behavioral context.

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 parameter semantics beyond the schema - it mentions 'AI outpainting' which relates to the 'extend' mode and 'background_prompt', and references 'platforms' which maps to 'target_format' enum values. However, it doesn't provide additional context about parameter interactions or usage patterns that aren't already in the schema descriptions.

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 clearly states the tool's function as 'Resize/reformat images for different platforms' with the specific method 'Uses AI outpainting to intelligently extend content for new aspect ratios.' It distinguishes from siblings like 'upscale_image' (resolution increase) and 'edit_image' (general editing) by focusing on platform-specific resizing with AI extension. However, it doesn't explicitly differentiate from 'inpaint_image' (which might also modify content).

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 context through the phrase 'for different platforms (like Canva Magic Resize)' and mentions alternative modes ('crop' and 'letterbox' coming soon), but it doesn't explicitly state when to use this tool versus siblings like 'compose_images' or 'edit_image'. The note about upcoming modes provides some guidance on current limitations, but lacks explicit when-to-use or when-not-to-use instructions.

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/raveenb/fal-mcp-server'

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