Skip to content

Image Processing

Resize, compress, convert, watermark and read image metadata.

Overview

Base path: /v1/image
Python namespace: infra.image_process
text
# Python
from infrai import infra

# TypeScript
import { InfraiClient } from "@infrai/sdk";
const client = new InfraiClient({ apiKey: process.env.INFRAI_API_KEY! });
// → client.image

Methods

image.process

POST /v1/image/process

Process an image: resize, compress, convert, watermark, rotate or remove background.

Python

python
infra.image_process.process(...)  # resize / compress / convert / watermark / rotate / removebg

TypeScript

typescript
client.image.resize(opts) | .compress(opts) | .convert(opts) | .watermark(opts) | .rotate(opts) | .removebg(opts)

Parameters

NameTypeRequiredDescription
inputImageRef { url? | base64? }
Required
Image reference as URL or base64.
widthnumberOptionalTarget width in pixels.
heightnumberOptionalTarget height in pixels.
format"jpeg" | "png" | "webp" | "avif"OptionalOutput image format.
qualitynumberOptionalCompression quality from 0 to 100.
idempotency_keystringOptionalOptional dedup key; identical retries return the same result.

Returns

ImageOpResult { image_url, mime, width?, height?, bytes }

Example

一次性前置(每个范例都假定已完成):

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

Read image dimensions, MIME type and EXIF metadata.

Python

python
infra.image_process.metadata(input=...)

TypeScript

typescript
client.image.metadata(opts: { input }): Promise<{ width, height, mime, exif? }>

Parameters

NameTypeRequiredDescription
inputImageRef { url? | base64? }
Required
Image reference as URL or base64.

Returns

{ width, height, mime, exif? }

Example

一次性前置(每个范例都假定已完成):

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"))