Skip to main content
Glama
duke0317

Image Processing MCP Server

by duke0317

apply_vignette

Adds a vignette effect to images by darkening edges with adjustable strength to create focus on central subjects. Supports various input sources and output formats.

Instructions

应用晕影效果

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_sourceYes图片源,可以是文件路径或base64编码的图片数据
strengthNo晕影强度,范围 0.0-1.0,值越大效果越明显
output_formatNo输出格式:PNG、JPEG、WEBP 等PNG

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core handler implementing vignette effect: pixel-by-pixel radial mask creation, Gaussian blur, colored overlay compositing with PIL.
    async def apply_vignette(arguments: Dict[str, Any]) -> List[TextContent]:
        """
        为图片添加暗角效果
        
        Args:
            arguments: 包含图片源和暗角参数的字典
            
        Returns:
            List[TextContent]: 处理结果
        """
        try:
            # 参数验证
            image_source = arguments.get("image_source")
            ensure_valid_image_source(image_source)
            
            intensity = arguments.get("intensity", 0.5)
            radius = arguments.get("radius", 0.7)
            color = arguments.get("color", "#000000")
            output_format = arguments.get("output_format", DEFAULT_IMAGE_FORMAT)
            
            # 验证参数
            validate_numeric_range(intensity, 0.0, 1.0, "intensity")
            validate_numeric_range(radius, 0.0, 1.0, "radius")
            validate_color_hex(color)
            
            # 加载图片
            processor = ImageProcessor()
            image = processor.load_image(image_source)
            
            # 转换为RGBA模式
            if image.mode != "RGBA":
                image = image.convert("RGBA")
            
            # 创建暗角遮罩
            mask = Image.new("L", image.size, 255)
            draw = ImageDraw.Draw(mask)
            
            # 计算中心点和半径
            center_x, center_y = image.width // 2, image.height // 2
            max_radius = min(image.width, image.height) // 2
            vignette_radius = int(max_radius * radius)
            
            # 创建径向渐变
            for y in range(image.height):
                for x in range(image.width):
                    # 计算到中心的距离
                    distance = ((x - center_x) ** 2 + (y - center_y) ** 2) ** 0.5
                    
                    # 计算暗角强度
                    if distance <= vignette_radius:
                        alpha = 255
                    else:
                        # 在半径外应用渐变
                        fade_distance = distance - vignette_radius
                        fade_ratio = min(fade_distance / (max_radius - vignette_radius), 1.0)
                        alpha = int(255 * (1 - intensity * fade_ratio))
                    
                    mask.putpixel((x, y), alpha)
            
            # 应用高斯模糊使暗角更自然
            mask = mask.filter(ImageFilter.GaussianBlur(radius=max_radius * 0.1))
            
            # 创建暗角图层
            vignette_rgb = tuple(int(color[i:i+2], 16) for i in (1, 3, 5))
            vignette_layer = Image.new("RGBA", image.size, vignette_rgb + (0,))
            
            # 应用遮罩
            vignette_layer.putalpha(mask)
            
            # 合成图片
            result_image = Image.alpha_composite(image, vignette_layer)
            
            # 转换为base64
            output_info = processor.output_image(result_image, "border", output_format)
            
            return [TextContent(
                type="text",
                text=json.dumps({
                    "success": True,
                    "message": "成功添加暗角效果",
                    "data": {
                        **output_info,
                        "metadata": {
                            "size": f"{image.width}x{image.height}",
                            "intensity": intensity,
                            "radius": radius,
                            "color": color,
                            "format": output_format
                        }
                    }
                }, ensure_ascii=False)
            )]
            
        except ValidationError as e:
            return [TextContent(
                type="text",
                text=json.dumps({
                    "success": False,
                    "error": f"参数验证失败: {str(e)}"
                }, ensure_ascii=False)
            )]
        except Exception as e:
            return [TextContent(
                type="text",
                text=json.dumps({
                    "success": False,
                    "error": f"添加暗角效果失败: {str(e)}"
                }, ensure_ascii=False)
            )]
  • main.py:603-623 (registration)
    MCP tool registration decorator @mcp.tool() defining the apply_vignette tool entrypoint, wrapping and calling the core effects handler.
    @mcp.tool()
    def apply_vignette(
        image_source: Annotated[str, Field(description="图片源,可以是文件路径或base64编码的图片数据")],
        strength: Annotated[float, Field(description="晕影强度,范围 0.0-1.0,值越大效果越明显", ge=0.0, le=1.0, default=0.5)],
        output_format: Annotated[str, Field(description="输出格式:PNG、JPEG、WEBP 等", default="PNG")]
    ) -> str:
        """应用晕影效果"""
        try:
            arguments = {
                "image_source": image_source,
                "strength": strength,
                "output_format": output_format
            }
            result = safe_run_async(effects_apply_vignette(arguments))
            return result[0].text
        except Exception as e:
            return json.dumps({
                "success": False,
                "error": f"应用晕影效果失败: {str(e)}"
            }, ensure_ascii=False, indent=2)
  • Detailed input schema definition for the vignette tool parameters including intensity, radius, color.
    Tool(
        name="apply_vignette",
        description="为图片添加暗角效果",
        inputSchema={
            "type": "object",
            "properties": {
                "image_source": {
                    "type": "string",
                    "description": "图片源(文件路径或base64编码)"
                },
                "intensity": {
                    "type": "number",
                    "description": "暗角强度(0.0-1.0)",
                    "minimum": 0.0,
                    "maximum": 1.0,
                    "default": 0.5
                },
                "radius": {
                    "type": "number",
                    "description": "暗角半径(0.0-1.0)",
                    "minimum": 0.0,
                    "maximum": 1.0,
                    "default": 0.7
                },
                "color": {
                    "type": "string",
                    "description": "暗角颜色(十六进制格式)",
                    "default": "#000000"
                },
                "output_format": {
                    "type": "string",
                    "description": "输出格式",
                    "enum": ["PNG", "JPEG", "WEBP"],
                    "default": "PNG"
                }
            },
            "required": ["image_source"]
        }
    ),
  • main.py:65-72 (helper)
    Import of the vignette handler from tools.effects module into main.py for use in the MCP wrapper.
    from tools.effects import (
        add_border as effects_add_border,
        create_silhouette as effects_create_silhouette,
        add_shadow  as effects_add_shadow,
        add_watermark as effects_add_watermark,
        apply_vignette as effects_apply_vignette,
        create_polaroid as effects_create_polaroid
    )
Behavior2/5

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

No annotations are provided, so the description carries full burden for behavioral disclosure. It only states the action ('apply vignette effect') without mentioning side effects, permissions, rate limits, or output behavior. For a mutation tool (applies visual effect to an image), this lack of transparency about what changes occur and any constraints 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 phrase in Chinese that directly states the tool's function. It's appropriately sized and front-loaded with zero wasted words, making it easy to parse quickly.

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 has an output schema (implied by 'Has output schema: true'), the description doesn't need to explain return values. However, as a mutation tool with no annotations and many sibling alternatives, the description is minimally adequate but lacks context about behavioral traits and usage differentiation, leaving clear gaps for the agent.

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 parameters are fully documented in the schema. The description adds no additional meaning about parameters beyond what's in the schema (e.g., no examples, no clarification of 'image_source' formats beyond file path/base64). 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.

Purpose3/5

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

The description '应用晕影效果' (apply vignette effect) states the verb and resource clearly but is vague about scope and differentiation. It doesn't specify whether this applies to a single image or batch, nor how it differs from similar sibling tools like 'apply_blur' or 'apply_edge_enhance'. The purpose is understandable but lacks specificity for sibling differentiation.

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?

No guidance is provided on when to use this tool versus alternatives. With many sibling image processing tools (e.g., apply_blur, adjust_brightness), the description offers no context about appropriate use cases, prerequisites, or exclusions. The agent must infer usage from the tool name 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/duke0317/ps-mcp'

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