Skip to content

旧版 PNG 接口

API PLAYGROUND

旧版 PNG 接口

POST /api/render

环境配置

Base URL 和 Authorization 修改后自动保存,供本站 Playground 共用。

服务地址,请求路径固定为 /api/render。
请求头配置
必填Bearer API Key,格式为 Bearer <API_KEY>。如何鉴权?
可选业务请求标识,省略时由服务生成。
请求体配置
必填 · FileContentLatest完整项目内容,对应文档中的 content。粘贴 JSON 或导入 .algeo 文件。
可选 · number从 1 开始的画板序号,留空使用默认值 1。
可选 · object渲染母版 JSON 对象,可从大角几何母版页面下载。
仅支持 2D PNG;自动模式省略 viewBound,使用画板保存的视口。
可选 · number每逻辑单位的像素数,正数;留空沿用画板相机缩放。
可选 · number输出设备像素比,正数;默认 1,只放大物理像素尺寸。

响应

发送请求后,在这里查看 HTTP 状态码和响应内容。

POST /api/render

Base URL: https://api.dajiaoai.com

接口地址: POST /api/render

推荐迁移到新版本

POST /api/render 保留用于兼容已有接入,仅支持 2D PNG。新接入请使用 POST /api/render/v2,已有调用建议在更新时迁移。

迁移到 v2

迁移时保留 contentslideIndextemplate,将 viewBound 的边界和顶层 scalepixelRatio 合并到 view2D,例如:

json
{
  "view2D": {
    "left": -10,
    "right": 10,
    "bottom": -10,
    "top": 10,
    "scale": 50,
    "pixelRatio": 2
  }
}

以上仅为视图参数片段,完整请求仍需包含 content。如需使用保存的相机,可同时省略 view2Dview3D;3D 输出使用 view3D。旧版顶层 pixelRatio 迁移到 view2D.pixelRatio,该字段可选,默认 1;3D 输出使用 view3D.pixelRatio

旧版请求参数

旧版接口的 AuthorizationContent-Typex-request-id 请求头,以及 contentslideIndextemplate 字段与新版 PNG 接口一致,此外还接收:

字段类型必填说明
viewBoundobject逻辑视口边界,格式为 { left, right, bottom, top },要求 left < rightbottom < top。省略时使用目标画板当前 camera。
scalenumber相机缩放比例(每逻辑单位对应的像素数),正数。省略时使用目标画板当前 camera.scale
pixelRationumber否,仅 /api/renderPNG 输出像素倍率,必须是正的有限数,默认 1。保持逻辑视口和相机缩放不变,将 PNG 的物理宽高按此倍率放大。SVG 和 TikZ 接口不接收此字段。

旧版请求与响应示例

bash
curl -X POST https://api.dajiaoai.com/api/render \
  -H "Authorization: Bearer djo_xxx" \
  -H "Content-Type: application/json" \
  -H "x-request-id: render-demo-001" \
  -d '{
    "slideIndex": 1,
    "viewBound": {
      "left": -10,
      "right": 10,
      "bottom": -10,
      "top": 10
    },
    "scale": 50,
    "pixelRatio": 2,
    "template": {
      "backgroundStyle": {
        "background": { "color": "#ffffff" },
        "grid": {},
        "xaxis": {},
        "yaxis": {}
      },
      "defaultStyle": {
        "types": [["Point", { "pointSize": 1, "color": "#000000" }]],
        "typeLabels": [],
        "textType": {},
        "sliderType": {},
        "buttonType": {}
      }
    },
    "content": {
      "metadata": { "version": "11" },
      "messages": [],
      "slides": [{ "definitions": [{ "kind": "primitive", "id": "A", "source": "Point(0, ?)", "label": "{{id}}" }, { "kind": "primitive", "id": "B", "source": "Point(?, 0)", "label": "{{id}}" }, { "kind": "primitive", "id": "C", "source": "Point(?, 0)", "label": "{{id}}" }, { "kind": "primitive", "id": "a", "source": "Segment(A, B)" }, { "kind": "primitive", "id": "b", "source": "Segment(B, C)" }, { "kind": "primitive", "id": "c", "source": "Segment(C, A)" }], "uvarMap": [["A.0", 3], ["B.0", -3], ["C.0", 2]], "styleSheet": { "background": {}, "xaxis": { "show": false }, "yaxis": { "show": false }, "grid": {}, "types": [], "typeLabels": [], "primitives": [], "primitiveLabels": [], "textType": {}, "texts": [], "sliderType": {}, "sliders": [], "buttonType": {}, "buttons": [] }, "doc": [], "camera": { "offset": [0, 0], "scale": 50 } }]
    }
  }'

成功返回 200 OK

json
{
  "success": true,
  "url": "https://dl.easeplay.vip/dajiao-open/dev/mcp/customer-id/session-id/4fa2bc.png",
  "filename": "4fa2bc.png",
  "objectKey": "dajiao-open/dev/mcp/customer-id/session-id/4fa2bc.png",
  "slideIndex": 1,
  "viewBound": {
    "left": -10,
    "right": 10,
    "bottom": -10,
    "top": 10
  },
  "width": 2000,
  "height": 2000,
  "scale": 50,
  "mimeType": "image/png",
  "size": 24831
}

pixelRatio 只改变 PNG 的物理像素尺寸,不改变 viewBound 或相机 scale。最终尺寸会四舍五入为整数:

text
width = round(logical canvas width × pixelRatio)
height = round(logical canvas height × pixelRatio)

本例的视口宽高均为 20 个逻辑单位,scale50,因此逻辑渲染尺寸为 1000 × 1000;当 pixelRatio2 时,返回的 widthheight 以及实际 PNG 尺寸均为 2000 × 2000。最终宽度和高度均不得超过 2048 像素。