Information
TextImage 服务
一个提供文本转图片功能的模型上下文协议服务器,可将任意文本转换为美观的图片格式。
功能
将文本转换为1080x1080尺寸的图片
自动计算文字大小和居中位置
支持自定义字体
生成图片可直接保存或显示
安装
pip install -r requirements.txt
使用方法
作为命令行工具
python src/text2image/text2image.py
在 Claude 桌面版中
添加到您的 Claude 桌面配置 (claude_desktop_config.json):
\{
"mcpServers": \{
"text2image": \{
"command": "uv",
"args": [
"--directory", "/absolute/path/to/text2image",
"run", "text2image.py"
]
\}
\}
\}
可用工具
text_to_image
将文本转换为图片
参数:
text (字符串, 必填): 要转换为图片的文本
text_color (字符串, 可选): 文字颜色,Hex格式,默认"#000000"
bg_color (字符串, 可选): 背景颜色,Hex格式,默认"#FFFFFF"
width (整数, 可选): 图片宽度,默认1080
height (整数, 可选): 图片高度,默认1080
font_size (整数, 可选): 字体大小,默认80
font_path (字符串, 可选): 字体文件路径,默认'simhei.ttf'
texture (字符串, 可选): 背景材质图片路径
output_path (字符串, 可选): 图片保存路径,未指定时默认保存为"output.png"
corner_radius (整数, 可选): 图片圆角半径,默认为0(直角)
JSON示例请求:
\{
"text": "示例
文本(可自带换行符控制换行位置)",
"text_color": "#FF0000",
"bg_color": "#FFFFFF",
"width": 800,
"height": 600,
"font_size": 60,
"font_path": "arial.ttf",
"texture": "background.jpg",
"output_path": "custom_output.png"
\}
返回值:
PIL.Image.Image: 生成的图片对象
开发
# 安装依赖
pip install -r requirements.txt
# 运行服务
python src/text2image/text2image.py
许可证
MIT 许可证
贡献
欢迎贡献!请随时提交 Pull Request。
"mcpServers": # TextImage 服务