# GET 请求 curl "https://your-worker.dev/api/generate?text=Hello&width=600&height=300&fontSize=48" --output image.svg # POST 请求(完整参数) curl -X POST "https://your-worker.dev/api/generate" \ -H "Content-Type: application/json" \ -d '{"text":"Hello\nWorld","width":800,"height":400,"fontSize":42,"fontWeight":700, "bgColor":"#1a1208","textColor":"#f5f0e8","padding":60,"gradient":"linear-gradient(135deg,#667eea,#764ba2)"}' --output image.svg
const res = await fetch('/api/generate', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ text: 'Hello World', width: 800, height: 400, fontSize: 42, fontWeight: 700, bgColor: '#000', textColor: '#fff', format: 'png' // svg | png | base64 | datauri }) }); const blob = await res.blob(); document.querySelector('img').src = URL.createObjectURL(blob);
import requests res = requests.post('https://your-worker.dev/api/generate', json={ 'text': 'Hello World', 'width': 800, 'height': 400, 'fontSize': 42, 'bgColor': '#1a1208', 'textColor': '#f5f0e8', }) with open('image.svg', 'w') as f: f.write(res.text)
text string* 必填,支持 \n 换行 width number 图片宽度 px(默认 800,最大 3000) height number 图片高度 px(默认 400,最大 3000) fontSize number 字体大小 px(默认 42) fontWeight number 字重 300/400/700/900(默认 400) lineHeight number 行高倍数(默认 1.6) textAlign string left/center/right(默认 center) bgColor string 背景色 #rrggbb(默认 #ffffff) textColor string 文字色 #rrggbb(默认 #000000) padding number 内边距 px(默认 40) borderRadius number 圆角 px(默认 0) gradient string CSS 渐变,覆盖 bgColor(linear-gradient(...)) bgImage string 背景图 URL 或 base64 data URI bgImageOpacity number 背景图透明度 0~1(默认 1.0) bgImageFit string cover/contain/fill/none(默认 cover) format string svg(默认) | png | base64 | datauri 响应 format=svg → image/svg+xml format=png → image/png 二进制流 format=base64 → JSON { data, dataUri, mimeType, width, height, size } format=datauri→ text/plain data URI 字符串 错误 → application/json { "error": "..." }
# fill 模式:居中裁剪到 400x400 curl "https://your-worker.dev/api/crop?url=https://example.com/img.jpg&w=400&h=400&mode=fill" --output out.png # fit 模式:保持比例,白边填充 curl "https://your-worker.dev/api/crop?url=https://example.com/img.jpg&w=800&h=400&mode=fit&bg=%23ffffff" --output out.png # POST JSON(取右下角锚点) curl -X POST "https://your-worker.dev/api/crop" \ -H "Content-Type: application/json" \ -d '{"url":"https://example.com/img.jpg","w":300,"h":300,"mode":"fill","gravity":"se"}' --output out.png
const res = await fetch('/api/crop', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ url: 'https://example.com/photo.jpg', w: 750, h: 1000, mode: 'fill', // fill | fit gravity: 'c', // nw n ne w c e sw s se format: 'png' // png | svg }) }); const blob = await res.blob(); document.querySelector('img').src = URL.createObjectURL(blob);
url string* 必填,源图片 http/https URL w number 输出宽度 px(1–4000,默认 800) h number 输出高度 px(1–4000,默认 800) mode string fill(裁剪填满)| fit(保比例留边)默认 fill 别名: fill=cover=thumb / fit=contain=pad gravity string 裁剪锚点 nw/n/ne/w/c/e/sw/s/se(默认 c 居中) ax/ay number 精确锚点百分比 0–100(覆盖 gravity) bg string fit 模式留边颜色 #rrggbb(默认 #000000) format string png(默认)| svg 响应 → image/png 二进制流(或 image/svg+xml) 响应头 X-Image-Width / X-Image-Height 包含实际输出尺寸 错误 → application/json { "error": "..." }
—
# 自动检测背景(透明图推荐) curl "https://your-worker.dev/api/bbox?url=https://example.com/icon.png&scale=1000" # 指定白色背景,容差 20 curl "https://your-worker.dev/api/bbox?url=https://example.com/img.jpg&bg=%23ffffff&tolerance=20" # POST JSON curl -X POST "https://your-worker.dev/api/bbox" \ -H "Content-Type: application/json" \ -d '{"url":"https://example.com/img.png","tolerance":10,"scale":1200}'
const res = await fetch('/api/bbox?' + new URLSearchParams({ url: 'https://example.com/icon.png', tolerance: 15, scale: 1000, })); const data = await res.json(); // { width, height, top, left, originalWidth, originalHeight, bgColor, alphaOnly } console.log(`内容区域: ${data.left},${data.top} ${data.width}x${data.height}`);
url string* 必填,源图片 http/https URL(支持 JPG/PNG/WebP) bg string 要过滤的背景色 #rrggbb(留空=自动检测四角颜色) tolerance number 颜色容差 0–255(默认 15,透明图设 0 即可) scale number 内部渲染精度 100–2000(默认 800,越大越精确) alphaOnly boolean true=仅用 alpha 通道 / false=仅颜色 / 留空=自动 透明 PNG/WebP → 无需传 bg,自动启用 alphaOnly 模式 纯色背景图 → 传 bg 颜色,调整 tolerance 响应 200 → application/json: { width, height, top, left, originalWidth, originalHeight, bgColor, alphaOnly, tolerance } 响应 422 → 整张图都是背景色(未找到内容) 错误 → application/json { "error": "..." }