Image Transformation
Transform images with a single API call. Send a file and an ordered list of operations — resize, crop, blur, sharpen, convert, and more — and receive the transformed image as base64-encoded JSON in the response.
Key Features
- AI Smart Crop — Automatically crop around faces, people, and animals using AI object detection. Priority: face > person > animal > object.
- AI Upscaling — Upscale images 2-4x with AI-powered super resolution for sharp, artifact-free results.
- AI Background Removal — Remove image backgrounds using AI segmentation. Output transparent PNG or composite onto a solid color.
- 24 Operations — Resize, crop, blur, sharpen, rotate, modulate, tint, threshold, denoise, opacity, and more.
- Pipeline Composition — Chain up to 30 operations in a single request, executed sequentially.
- Compress to Size — Iteratively compress an image to fit within a target file size in bytes.
- Format Conversion — Convert between PNG, JPEG, WebP, AVIF, and HEIF with quality control.
Overview
The Image Transformation API applies a pipeline of operations to an image. You send a file (base64 or URL) and an ordered list of operations, and receive the transformed image as base64-encoded JSON in the response.
Endpoint: POST /image-transformation/v1/transform
Supported formats: JPEG, PNG, WebP, GIF, AVIF, HEIF
Limits:
- Max file size: 50 MB
- Max request body: 60 MB
- Max operations per request: 30
Request Format
curl -X POST https://api.iterationlayer.com/image-transformation/v1/transform \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"file": {
"name": "photo.jpg",
"base64": "<base64-encoded-image>"
},
"operations": [
{ "type": "resize", "width_in_px": 800, "height_in_px": 600, "fit": "cover" },
{ "type": "convert", "format": "webp", "quality": 85 }
]
}'import { IterationLayer } from "iterationlayer";
const client = new IterationLayer({ apiKey: "YOUR_API_KEY" });
const result = await client.transform({
file: {
type: "base64",
name: "photo.jpg",
base64: "<base64-encoded-image>",
},
operations: [
{ type: "resize", width_in_px: 800, height_in_px: 600, fit: "cover" },
{ type: "convert", format: "webp", quality: 85 },
],
});
// result.data.buffer is base64-encoded, result.data.mime_type is "image/webp"from iterationlayer import IterationLayer
client = IterationLayer(api_key="YOUR_API_KEY")
result = client.transform(
file={
"type": "base64",
"name": "photo.jpg",
"base64": "<base64-encoded-image>",
},
operations=[
{"type": "resize", "width_in_px": 800, "height_in_px": 600, "fit": "cover"},
{"type": "convert", "format": "webp", "quality": 85},
],
)
# result["data"]["buffer"] is base64-encoded, result["data"]["mime_type"] is "image/webp"import il "github.com/iterationlayer/sdk-go"
client := il.NewClient("YOUR_API_KEY")
result, err := client.Transform(il.TransformRequest{
File: il.NewFileFromBase64("photo.jpg", "<base64-encoded-image>"),
Operations: []il.TransformOperation{
il.NewResizeOperation(800, 600, "cover"),
il.NewConvertOperation("webp"),
},
})
// result.Data.Buffer is base64-encoded, result.Data.MimeType is "image/webp"Top-Level Fields
| Field | Type | Required | Description |
|---|---|---|---|
file |
object | Yes | Image file to transform (see File Input below) |
operations |
array | Yes | Ordered list of operations to apply (max 30) |
webhook_url |
string | No | HTTPS URL to receive results asynchronously. If provided, returns 201 immediately. See Webhooks. |
Async Mode
Add a webhook_url parameter to process the request in the background. The API returns 201 Accepted immediately and delivers the result to your webhook URL when processing completes. See Webhooks for payload format and retry behavior.
File Input
Provide the image as either base64 or a URL:
| Field | Type | Required | Description |
|---|---|---|---|
name |
string | Yes |
Filename with extension (e.g., photo.jpg) |
base64 |
string | One of base64/url | Base64-encoded file content |
url |
string | One of base64/url | URL to fetch the file from |
URL Example
{
"file": {
"name": "photo.jpg",
"url": "https://example.com/photo.jpg"
},
"operations": [
{ "type": "grayscale" }
]
}
Operations
Operations are applied sequentially in the order provided.
resize
Resize the image to target dimensions.
| Field | Type | Required | Description |
|---|---|---|---|
width_in_px |
integer | Yes | Target width (> 0) |
height_in_px |
integer | Yes | Target height (> 0) |
fit |
string | Yes |
One of: cover, contain, fill, inside, outside |
Fit modes:
-
cover— Scale and crop to fill the target dimensions exactly -
contain— Scale to fit within dimensions, padding with black -
fill— Stretch to fill dimensions (may distort) -
inside— Scale down only if larger than target -
outside— Scale up only if smaller than target
{ "type": "resize", "width_in_px": 400, "height_in_px": 300, "fit": "cover" }
crop
Extract a rectangular region from the image.
| Field | Type | Required | Description |
|---|---|---|---|
left_in_px |
integer | Yes | Left offset (>= 0) |
top_in_px |
integer | Yes | Top offset (>= 0) |
width_in_px |
integer | Yes | Crop width (> 0) |
height_in_px |
integer | Yes | Crop height (> 0) |
{ "type": "crop", "left_in_px": 100, "top_in_px": 50, "width_in_px": 400, "height_in_px": 300 }
smart_crop
Intelligent crop that centers on detected objects (faces, people, animals). Falls back to center crop when no objects are detected. Uses AI object detection.
| Field | Type | Required | Description |
|---|---|---|---|
width_in_px |
integer | Yes | Target width (> 0) |
height_in_px |
integer | Yes | Target height (> 0) |
Priority order: face > person > animal > object
{ "type": "smart_crop", "width_in_px": 300, "height_in_px": 300 }
extend
Add padding around the image with a background color.
| Field | Type | Required | Description |
|---|---|---|---|
top_in_px |
integer | Yes | Top padding (>= 0) |
bottom_in_px |
integer | Yes | Bottom padding (>= 0) |
left_in_px |
integer | Yes | Left padding (>= 0) |
right_in_px |
integer | Yes | Right padding (>= 0) |
hex_color |
string | Yes |
Background color (e.g., #FF0000) |
{ "type": "extend", "top_in_px": 20, "bottom_in_px": 20, "left_in_px": 20, "right_in_px": 20, "hex_color": "#FFFFFF" }
trim
Remove borders from the image based on a color similarity threshold.
| Field | Type | Required | Description |
|---|---|---|---|
threshold |
integer | Yes | Color difference threshold (>= 0) |
{ "type": "trim", "threshold": 10 }
rotate
Rotate the image by any angle. Non-90-degree rotations expand the canvas.
| Field | Type | Required | Description |
|---|---|---|---|
angle_in_degrees |
float | Yes | Rotation angle |
hex_color |
string | No | Background color for exposed areas (default: black) |
{ "type": "rotate", "angle_in_degrees": 45.0, "hex_color": "#FFFFFF" }
flip
Mirror the image vertically (top to bottom).
{ "type": "flip" }
flop
Mirror the image horizontally (left to right).
{ "type": "flop" }
blur
Apply Gaussian blur.
| Field | Type | Required | Description |
|---|---|---|---|
sigma |
float | Yes | Blur radius (> 0) |
{ "type": "blur", "sigma": 3.0 }
sharpen
Sharpen the image.
| Field | Type | Required | Description |
|---|---|---|---|
sigma |
float | Yes | Sharpen intensity (> 0) |
{ "type": "sharpen", "sigma": 2.0 }
modulate
Adjust brightness, saturation, and/or hue. At least one parameter must be provided.
| Field | Type | Required | Description |
|---|---|---|---|
brightness |
float | No | Brightness multiplier (1.0 = unchanged) |
saturation |
float | No | Saturation multiplier (1.0 = unchanged) |
hue |
float | No | Hue rotation in degrees |
{ "type": "modulate", "brightness": 1.2, "saturation": 0.8 }
tint
Apply a color tint to the image.
| Field | Type | Required | Description |
|---|---|---|---|
hex_color |
string | Yes |
Tint color (e.g., #FF6600) |
{ "type": "tint", "hex_color": "#FF6600" }
grayscale
Convert the image to grayscale.
{ "type": "grayscale" }
invert_colors
Invert all colors in the image.
{ "type": "invert_colors" }
auto_contrast
Automatically adjust contrast by normalizing the histogram.
{ "type": "auto_contrast" }
gamma
Apply gamma correction.
| Field | Type | Required | Description |
|---|---|---|---|
gamma |
float | Yes | Gamma value (> 0, typical: 0.5-3.0) |
{ "type": "gamma", "gamma": 2.2 }
remove_transparency
Flatten the alpha channel against a background color. No-op if the image has no alpha channel.
| Field | Type | Required | Description |
|---|---|---|---|
hex_color |
string | Yes | Background color |
{ "type": "remove_transparency", "hex_color": "#FFFFFF" }
threshold
Convert pixels to black or white based on a brightness threshold.
| Field | Type | Required | Description |
|---|---|---|---|
value |
integer | Yes | Threshold value (0-255) |
is_grayscale |
boolean | Yes | Convert to grayscale before thresholding |
{ "type": "threshold", "value": 128, "is_grayscale": true }
denoise
Reduce noise using a median filter.
| Field | Type | Required | Description |
|---|---|---|---|
size |
integer | Yes | Filter window size (> 0, odd numbers recommended) |
{ "type": "denoise", "size": 3 }
opacity
Adjust the image opacity.
| Field | Type | Required | Description |
|---|---|---|---|
opacity_in_percent |
integer | Yes | Opacity level (0-100) |
{ "type": "opacity", "opacity_in_percent": 50 }
convert
Convert the image to a different format.
| Field | Type | Required | Description |
|---|---|---|---|
format |
string | Yes |
One of: png, jpeg, webp, avif, heif |
quality |
integer | No | Compression quality (1-100, for jpeg/webp) |
{ "type": "convert", "format": "webp", "quality": 85 }
upscale
Upscale the image using AI-powered super resolution.
| Field | Type | Required | Description |
|---|---|---|---|
factor |
integer | Yes | Scale factor: 2, 3, or 4 |
{ "type": "upscale", "factor": 4 }
compress_to_size
Iteratively compress an image to fit within a target file size. For lossy formats (JPEG, WebP) reduces quality first, then dimensions. For lossless formats (PNG, GIF) reduces dimensions only.
| Field | Type | Required | Description |
|---|---|---|---|
max_file_size_in_bytes |
integer | Yes | Maximum output size in bytes |
{ "type": "compress_to_size", "max_file_size_in_bytes": 500000 }
remove_background
Remove the image background using AI segmentation. Isolates the foreground subject and composites against a solid color or produces a transparent result.
The output format matches the input format. For formats that do not support transparency (JPEG, GIF), the background is filled with white unless hex_color is specified. To get a transparent result, convert to PNG or WebP first using the convert operation.
| Field | Type | Required | Description |
|---|---|---|---|
background_hex_color |
string | No |
Background replacement color (e.g., #FFFFFF). Omit for transparent (PNG/WebP only). |
{ "type": "remove_background" }
With background color:
{ "type": "remove_background", "background_hex_color": "#FFFFFF" }
Transparent output (convert to PNG first if input is JPEG):
[
{ "type": "convert", "format": "png" },
{ "type": "remove_background" }
]
Recipes
For complete, runnable examples see the Recipes page.
- Optimize Product Photos – Resize, sharpen, and compress product images for e-commerce listings.
- Generate Responsive Thumbnails – Create multiple thumbnail sizes from a single source image.
- Convert Image Formats at Scale – Batch convert images between formats like PNG, JPEG, and WebP.
- Batch Watermark Images – Apply watermarks to images in bulk for brand protection.
- Create Social Media Variants – Resize and crop images for different social media platform requirements.
Error Responses
| Status | Description |
|---|---|
| 400 | Invalid request (missing file, invalid operations, unsupported format) |
| 401 | Missing or invalid API key |
| 422 | Processing error (image too small for crop, invalid color, etc.) |
| 429 | Rate limit exceeded |