adjust_saturation
Adjust image saturation levels to enhance or reduce color intensity. Modify saturation factor to create vibrant visuals or grayscale effects for image processing workflows.
Instructions
调整图片饱和度
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image_source | Yes | 图片源,可以是文件路径或base64编码的图片数据 | |
| factor | Yes | 饱和度调整因子,1.0为原始饱和度,>1.0增强,<1.0减弱,0为灰度 |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- tools/color_adjust.py:345-398 (handler)Core handler function that validates input, loads the image using ImageProcessor, applies saturation adjustment with PIL's ImageEnhance.Color.enhance(factor), generates output image data, and returns JSON result.
async def adjust_saturation(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.Color(image) enhanced_image = enhancer.enhance(factor) # 输出处理后的图片 output_info = processor.output_image(enhanced_image, "saturation") result = { "success": True, "message": f"饱和度调整成功: 因子 {factor}", "data": { **output_info, "saturation_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:414-428 (registration)MCP server tool registration using FastMCP's @mcp.tool() decorator. This synchronous wrapper calls the async handler from tools.color_adjust via safe_run_async and handles errors.
@mcp.tool() def adjust_saturation( image_source: Annotated[str, Field(description="图片源,可以是文件路径或base64编码的图片数据")], factor: Annotated[float, Field(description="饱和度调整因子,1.0为原始饱和度,>1.0增强,<1.0减弱,0为灰度", ge=0)] ) -> str: """调整图片饱和度""" try: result = safe_run_async(color_adjust_saturation(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) - tools/color_adjust.py:65-84 (schema)Input schema definition for the adjust_saturation tool in the get_color_adjust_tools() function (possibly legacy or internal). Defines JSON schema with image_source (string) and factor (number 0.0-2.0).
Tool( name="adjust_saturation", description="调整图片饱和度", inputSchema={ "type": "object", "properties": { "image_source": { "type": "string", "description": "图片数据(base64编码)或文件路径" }, "factor": { "type": "number", "description": "饱和度调整因子(0.0-2.0,1.0为原始饱和度,0.0为灰度)", "minimum": 0.0, "maximum": 2.0 } }, "required": ["image_source", "factor"] } ),