图像处理
缩放、压缩、转换、加水印与读取图像元数据。
概览
基础路径:
/v1/imagePython 命名空间:
infra.image_processtext
# Python
from infrai import infra
# TypeScript
import { InfraiClient } from "@infrai/sdk";
const client = new InfraiClient({ apiKey: process.env.INFRAI_API_KEY! });
// → client.image方法
image.process
POST /v1/image/process
处理图像:缩放、压缩、转换、加水印、旋转或去背景。
Python
python
infra.image_process.process(...) # resize / compress / convert / watermark / rotate / removebgTypeScript
typescript
client.image.resize(opts) | .compress(opts) | .convert(opts) | .watermark(opts) | .rotate(opts) | .removebg(opts)参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
input | ImageRef { url? | base64? } | 必填 | 图像引用,URL 或 base64。 |
width | number | 可选 | 目标宽度(像素)。 |
height | number | 可选 | 目标高度(像素)。 |
format | "jpeg" | "png" | "webp" | "avif" | 可选 | 输出图像格式。 |
quality | number | 可选 | 压缩质量,0 到 100。 |
idempotency_key | string | 可选 | 可选去重 key;相同重试将返回同一结果。 |
返回
ImageOpResult { image_url, mime, width?, height?, bytes }示例
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
out = infra.image_process.resize(input={"url": "https://ex.com/photo.jpg"}, width=800)
print("image url:", out.get("image_url"))image.metadata
POST /v1/image/metadata
读取图像尺寸、MIME 类型与 EXIF 元数据。
Python
python
infra.image_process.metadata(input=...)TypeScript
typescript
client.image.metadata(opts: { input }): Promise<{ width, height, mime, exif? }>参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
input | ImageRef { url? | base64? } | 必填 | 图像引用,URL 或 base64。 |
返回
{ width, height, mime, exif? }示例
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import infra
meta = infra.image_process.metadata(input={"url": "https://ex.com/photo.jpg"})
print(meta.get("width"), "x", meta.get("height"), meta.get("mime"))