Skip to main content
Glama

adjust_sharpness

Adjust image sharpness by applying a factor to enhance or reduce edge definition for clearer or softer visual results.

Instructions

调整图片锐度

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_sourceYes图片源,可以是文件路径或base64编码的图片数据
factorYes锐度调整因子,1.0为原始锐度,>1.0增强,<1.0减弱

Implementation Reference

  • Core handler implementation: validates inputs, loads image, applies PIL ImageEnhance.Sharpness with given factor, outputs processed image as base64 JSON.
    async def adjust_sharpness(image_source: str, factor: float) -> list[TextContent]: """ 调整图片锐度 Args: image_source: 图片数据(base64编码)或文件路径 factor: 锐度调整因子(0.0-2.0) Returns: 调整后的图片数据 """ try: # 验证参数 if not image_source: raise ValidationError("图片数据不能为空") if not validate_numeric_range(factor, 0.0, 2.0): raise ValidationError(f"锐度因子必须在0.0-2.0范围内: {factor}") # 加载图片 image = processor.load_image(image_source) # 调整锐度 enhancer = ImageEnhance.Sharpness(image) enhanced_image = enhancer.enhance(factor) # 输出处理后的图片 output_info = processor.output_image(enhanced_image, "sharpness") result = { "success": True, "message": f"锐度调整成功: 因子 {factor}", "data": { **output_info, "sharpness_factor": factor, "size": image.size } } return [TextContent(type="text", text=json.dumps(result, ensure_ascii=False))] except ValidationError as e: error_result = { "success": False, "error": f"参数验证失败: {str(e)}" } return [TextContent(type="text", text=json.dumps(error_result, ensure_ascii=False))] except Exception as e: error_result = { "success": False, "error": f"锐度调整失败: {str(e)}" } return [TextContent(type="text", text=json.dumps(error_result, ensure_ascii=False))]
  • main.py:429-442 (registration)
    Registers the tool with FastMCP using @mcp.tool(). Defines input schema via Annotated fields and wraps the async handler call with safe_run_async for sync compatibility.
    @mcp.tool() def adjust_sharpness( image_source: Annotated[str, Field(description="图片源,可以是文件路径或base64编码的图片数据")], factor: Annotated[float, Field(description="锐度调整因子,1.0为原始锐度,>1.0增强,<1.0减弱", gt=0)] ) -> str: """调整图片锐度""" try: result = safe_run_async(color_adjust_sharpness(image_source, factor)) return result[0].text except Exception as e: return json.dumps({ "success": False, "error": f"调整锐度失败: {str(e)}" }, ensure_ascii=False, indent=2)
  • Explicit JSON schema definition for the adjust_sharpness tool input, used in get_color_adjust_tools() function (though registration uses Pydantic in main.py).
    Tool( name="adjust_sharpness", description="调整图片锐度", inputSchema={ "type": "object", "properties": { "image_source": { "type": "string", "description": "图片数据(base64编码)或文件路径" }, "factor": { "type": "number", "description": "锐度调整因子(0.0-2.0,1.0为原始锐度)", "minimum": 0.0, "maximum": 2.0 } }, "required": ["image_source", "factor"] } ),

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