Skip to main content
The resize operation generates one or more output images from a single source. You can target explicit pixel widths, scale by a percentage, or cap the output height while resizing to a given width.

Parameters

operation
string
required
Must be "resize".
input
string
required
Path to the source image.
output_dir
string
required
Directory where resized files will be written. One file is produced per width.
widths
number[]
Array of target widths in pixels. Aspect ratio is preserved. Either widths or scale_percent is required.
scale_percent
number
Scale factor as a percentage. 50 produces an image at half the original dimensions. Either widths or scale_percent is required.
max_height
number
Maximum output height in pixels. When set, a width that would produce a taller image is capped at this value, effectively reducing the output width proportionally.
format
string
default:"same as input"
Output format: png, jpeg, webp, or avif. Defaults to the source image format.
quality
number
default:"85"
Encode quality for JPEG and WebP outputs. Range: 1–100.
filter
string
default:"lanczos3"
Resampling filter used when downscaling or upscaling.
ValueDescription
lanczos3High-quality Lanczos resampler (default)
catmullromSmooth cubic spline, slightly faster
defaultEngine default (nearest-neighbor for speed)
linear_rgb
boolean
default:"false"
When true, resize is performed in linear light (gamma-decoded) rather than gamma-encoded sRGB. Produces more accurate brightness at edges and gradients.
inline
boolean
default:"false"
When true, each output file is also returned as a base64-encoded string in data_base64.
Enable linear_rgb when downscaling photographs. Resizing in gamma-encoded sRGB causes mid-tones to appear darker than they should — linear light processing corrects this at a small CPU cost.

Go client

Client.Resize()

Resize a source image to one or more explicit widths.
func (c *Client) Resize(ctx context.Context, input, outputDir string, widths []uint32) (*JobResult, error)

Client.ResizePercent()

Scale an image by a percentage factor.
func (c *Client) ResizePercent(ctx context.Context, input, outputDir string, percent float32) (*JobResult, error)

Client.ResizeLinear()

Resize using linear RGB color space for higher-quality results.
func (c *Client) ResizeLinear(ctx context.Context, input, outputDir string, widths []uint32) (*JobResult, error)
For full control over all parameters, build a ResizeJob directly and call Client.Execute():
type ResizeJob struct {
    Operation    string   `json:"operation"`
    Input        string   `json:"input"`
    OutputDir    string   `json:"output_dir"`
    Widths       []uint32 `json:"widths,omitempty"`
    ScalePercent *float32 `json:"scale_percent,omitempty"`
    MaxHeight    *uint32  `json:"max_height,omitempty"`
    Format       *string  `json:"format,omitempty"`
    Quality      *uint8   `json:"quality,omitempty"`
    Filter       *string  `json:"filter,omitempty"`
    LinearRGB    bool     `json:"linear_rgb,omitempty"`
    Inline       bool     `json:"inline,omitempty"`
}

Examples

Multiple widths

Generate four WebP variants for responsive delivery.
{
  "operation": "resize",
  "input": "photo.jpg",
  "output_dir": "dist/images",
  "widths": [320, 640, 1024, 1920],
  "format": "webp",
  "quality": 85,
  "linear_rgb": true
}

Scale by percentage

Produce a thumbnail at 50% of the original dimensions.
{
  "operation": "resize",
  "input": "photo.jpg",
  "output_dir": "dist/images",
  "scale_percent": 50,
  "format": "png"
}

Max height constraint

Resize to 1200 px wide but never taller than 800 px.
{
  "operation": "resize",
  "input": "photo.jpg",
  "output_dir": "dist/images",
  "widths": [1200],
  "max_height": 800,
  "format": "jpeg",
  "quality": 90
}

Build docs developers (and LLMs) love