Skip to main content
Glama

adjust_brightness

Modify image brightness by specifying a factor with the Image Processing MCP Server. Input an image source and adjust the brightness level (greater than 1.0 to brighten, less than 1.0 to darken) for precise image enhancement.

Instructions

调整图片亮度

Input Schema

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

Implementation Reference

  • Core handler function that loads the image, applies brightness enhancement using PIL ImageEnhance.Brightness, processes output, and returns JSON result.
    async def adjust_brightness(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.Brightness(image) enhanced_image = enhancer.enhance(factor) # 输出处理后的图片 output_info = processor.output_image(enhanced_image, "brightness") result = { "success": True, "message": f"亮度调整成功: 因子 {factor}", "data": { **output_info, "brightness_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))] async def adjust_opacity(image_source: str, opacity: float) -> list[TextContent]: """ 调整图片不透明度 Args: image_source: 图片数据(base64编码)或文件路径 opacity: 不透明度值(0.0-1.0) Returns: 调整后的图片数据 """ try: # 验证参数 if not image_source: raise ValidationError("图片数据不能为空") if not validate_numeric_range(opacity, 0.0, 1.0): raise ValidationError(f"不透明度值必须在0.0-1.0范围内: {opacity}") # 加载图片 image = processor.load_image(image_source) original_mode = image.mode # 确保图片有alpha通道 if image.mode != 'RGBA': image = image.convert('RGBA') # 获取图片数据 data = image.getdata() # 调整alpha通道 new_data = [] for item in data: # item是(R, G, B, A)元组 r, g, b, a = item # 计算新的alpha值 new_alpha = int(a * opacity) new_data.append((r, g, b, new_alpha)) # 创建新图片 opacity_image = Image.new('RGBA', image.size) opacity_image.putdata(new_data) # 输出处理后的图片 output_info = processor.output_image(opacity_image, "opacity") result = { "success": True, "message": f"不透明度调整成功: {opacity}", "data": { **output_info, "opacity_value": opacity, "original_mode": original_mode, "new_mode": opacity_image.mode, "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))] 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:384-398 (registration)
    Registers the 'adjust_brightness' tool with FastMCP server using @mcp.tool() decorator. Wraps the async handler in a synchronous function with input validation via Annotated types.
    @mcp.tool() def adjust_brightness( 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_brightness(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)
  • Defines the input schema for the adjust_brightness tool, including parameters and validation constraints (though registration uses function annotations).
    Tool( name="adjust_brightness", 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