Skip to content

Latest commit

 

History

History
105 lines (84 loc) · 4.24 KB

API.md

File metadata and controls

105 lines (84 loc) · 4.24 KB

PixelMCP Bridge — 插件接口文档(HTTP JSON-RPC)

这是对外预留的插件接口:任何程序(不限于 AI/MCP)都可以用 HTTP 驱动 Pixelorama。 桥接只监听 127.0.0.1,端口在 8765-8774 中自动选择(被占用时顺延)。

接入

GET  http://127.0.0.1:8765/health      # 探活
POST http://127.0.0.1:8765/rpc         # 所有操作

请求体(JSON):

{"method": "draw_stroke", "params": {"points": [[0,0],[3,3]], "color": "#ff0000"}, "id": 1}

响应体:

{"id": 1, "result": {...}}           // 成功
{"id": 1, "error": {"code": -32602, "message": "..."}}   // 失败

POST /rpc 必须使用 Content-Type: application/json。接口只支持本机程序,不接受浏览器的跨站请求。Windows 外部程序可以按 启动器调用示例 启动编辑器,并使用启动器返回的 base_url 访问 HTTP 接口。Android 请按 USB 连接指南 转发。

方法一览

状态

方法 参数 说明
ping - 连通性
get_info - 版本、画布尺寸、当前工具/颜色/图层/帧
get_tools - 全部工具注册表
list_palettes - 已安装调色板
get_palette_colors - 当前调色板全部颜色(hex)

工具与颜色(与人在 UI 里点击完全等价)

方法 参数 说明
set_tool tool 切换左键工具,如 Pencil/Eraser/Bucket/LineTool(别名 Line)/RectangleTool(别名 Rectangle)/EllipseTool(别名 Ellipse)
set_color primary, secondary 设置颜色,hex 如 #ff0000 / #ff000080

绘制(每次调用一个撤销步骤,与手绘一致)

方法 参数 说明
draw_stroke points, color?, size?, tool?(默认 Pencil) 逐点画线,points 形如 [[0,0],[1,1]]
erase_stroke points, size? 橡皮擦
draw_line from, to, color?, size? 直线工具
draw_rect from, to, color?, size? 矩形描边
draw_ellipse from, to, color?, size? 椭圆(外接框)
fill at, color? 油漆桶填充
pick_color at 读取画布某点颜色

项目与文件

方法 参数 说明
new_project width, height, name?, fill_color? 新建项目并切换到它
open_file path 打开 png/pxo 等(等同 文件→打开)
save_pxo path 保存 .pxo
export_png path, frame?, layer? 导出某格图层为 PNG
resize_canvas width, height 画布尺寸

画布读写(AI 落图入口)

方法 参数 说明
get_pixels frame?, layer? 读当前格图层 → png_base64
set_layer_image image_base64, as_new_layer?, layer?, frame?, x?, y?, layer_name? 把 PNG(base64)落到图层;可撤销

伪像素 → 真像素

方法 参数 说明
pixelize image_base64 或 path, width, height, max_colors?, palette_colors?, dither? 返回 png_base64
pixelize_to_canvas 同上 + layer_name? 转换后直接落为画布新图层

图层

方法 参数 说明
get_layers - 列表(index/name/visible/opacity/locked/type)
add_layer name?, on_top? 新建像素图层
remove_layer index? 删除(可撤销)
set_layer_props index?, visible?, opacity?, name?, locked? 修改属性

历史与帧

方法 参数 说明
undo / redo - 与 Ctrl+Z / Ctrl+Shift+Z 等价
select_frame frame 切换动画帧
add_frame - 新建空帧

curl 示例

curl -s http://127.0.0.1:8765/health
curl -s -X POST http://127.0.0.1:8765/rpc -H "Content-Type: application/json" \
  -d '{"method":"new_project","params":{"width":32,"height":32},"id":1}'
curl -s -X POST http://127.0.0.1:8765/rpc -H "Content-Type: application/json" \
  -d '{"method":"draw_ellipse","params":{"from":[2,2],"to":[29,29],"color":"#e74c3c"},"id":2}'

安全说明

桥接只绑定 127.0.0.1(本机回环),外部设备无法直接访问。它能完全控制 Pixelorama(读写文件),请只在你信任的本机环境启用。