Skip to main content
Glama

flip_image

Flip images horizontally or vertically to correct orientation, create mirror effects, or adjust visual layouts for various applications.

Instructions

翻转图片

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
image_sourceYes图片源,可以是文件路径或base64编码的图片数据
directionYes翻转方向:horizontal(水平翻转)或 vertical(垂直翻转)

Implementation Reference

  • Core handler function that performs the actual image flipping using PIL.Image.transpose based on direction (horizontal or vertical). Loads image, applies flip, outputs result via ImageProcessor, returns JSON response.
    async def flip_image(image_data: str, direction: str) -> list[TextContent]: """ 翻转图片 Args: image_data: 图片数据(base64编码) direction: 翻转方向(horizontal, vertical) Returns: 翻转后的图片数据 """ try: # 验证参数 if not image_data: raise ValidationError("图片数据不能为空") if direction not in ['horizontal', 'vertical']: raise ValidationError(f"无效的翻转方向: {direction}") # 加载图片 image = processor.load_image(image_data) # 翻转图片 if direction == 'horizontal': flipped_image = image.transpose(Image.FLIP_LEFT_RIGHT) direction_desc = "水平翻转" else: # vertical flipped_image = image.transpose(Image.FLIP_TOP_BOTTOM) direction_desc = "垂直翻转" # 输出翻转后的图片 output_info = processor.output_image(flipped_image, f"flip_{direction}") result = { "success": True, "message": f"图片{direction_desc}成功", "data": { **output_info, "direction": direction, "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:223-236 (registration)
    MCP tool registration using @mcp.tool() decorator. This wrapper function handles the tool call, delegates to the core transform_flip_image handler, and formats the response as string.
    @mcp.tool() def flip_image( image_source: Annotated[str, Field(description="图片源,可以是文件路径或base64编码的图片数据")], direction: Annotated[str, Field(description="翻转方向:horizontal(水平翻转)或 vertical(垂直翻转)")] ) -> str: """翻转图片""" try: result = safe_run_async(transform_flip_image(image_source, direction)) return result[0].text except Exception as e: return json.dumps({ "success": False, "error": f"翻转图片失败: {str(e)}" }, ensure_ascii=False, indent=2)
  • Input schema definition for the flip_image tool, specifying parameters image_data (base64 string) and direction (enum: horizontal, vertical). Part of get_transform_tools().
    Tool( name="flip_image", description="翻转图片", inputSchema={ "type": "object", "properties": { "image_data": { "type": "string", "description": "图片数据(base64编码)" }, "direction": { "type": "string", "description": "翻转方向(horizontal, vertical)", "enum": ["horizontal", "vertical"] } }, "required": ["image_data", "direction"] } )

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