Resizing & Cropping

This page documents all operations for controlling image dimensions, aspect ratio, cropping, and positioning.

Resize

rs:%resizing_type:%width:%height:%enlarge:%extend

The main resizing operation. Combines resizing type, width, height, enlarge, and extend into a single directive. All parameters are optional and can be omitted to use their defaults.

Parameter
Type
Default
Allowed Values

resizing_type

string

fit

fit, fill, fill-down, force, auto

width

integer

0

Any positive integer, or 0 for auto

height

integer

0

Any positive integer, or 0 for auto

enlarge

boolean

false

1, t, true to enable

extend

compound

false:ce:0:0

See Extend

Examples:

# Fit within 300x200, keep aspect ratio
rs:fit:300:200

# Fill exactly 400x400, cropping excess
rs:fill:400:400

# Force exact dimensions (may distort)
rs:force:500:300

# Fit within 300x200, allow enlarging small images
rs:fit:300:200:1

Rewrite rule example:

Regex: ^/thumbnail/(\d+)x(\d+)/(.*) Target: /_sx/img/_/rs:fit:$1:$2/q:80/plain/$3


Size

Shorthand for width, height, enlarge, and extend — without specifying a resizing type. Uses the current resizing type (default: fit).

Parameter
Type
Default
Allowed Values

width

integer

0

Any positive integer, or 0 for auto

height

integer

0

Any positive integer, or 0 for auto

enlarge

boolean

false

1, t, true to enable

extend

compound

false:ce:0:0

See Extend

Example:


Resizing Type

Defines how smoxy resizes the source image. Can be set independently or as part of the rs operation.

Parameter
Type
Default
Allowed Values

resizing_type

string

fit

fit, fill, fill-down, force, auto

Resizing types explained

Type
Behavior

fit

Resizes the image to fit entirely within the given dimensions while keeping the aspect ratio. The result will be equal to or smaller than the specified size.

fill

Resizes the image to completely fill the given dimensions while keeping the aspect ratio. Parts that extend beyond the target size are cropped.

fill-down

Same as fill, but if the resized image is smaller than the requested size, it crops the result to maintain the requested aspect ratio.

force

Resizes to the exact dimensions without keeping the aspect ratio. This may distort the image.

auto

If both source and result have the same orientation (both portrait or both landscape), uses fill. Otherwise, uses fit.

Example:


Width

Sets the width of the resulting image independently. When set to 0, smoxy calculates the width from the defined height and the source aspect ratio.

Parameter
Type
Default
Allowed Values

width

integer

0

Any positive integer, or 0 for auto

Example:

Rewrite rule example:

Regex: ^/w/(\d+)/(.*) Target: /_sx/img/_/w:$1/q:80/plain/$2

A request to /w/800/media/photo.jpg resizes the image to 800px width.


Height

Sets the height of the resulting image independently. When set to 0, smoxy calculates the height from the defined width and the source aspect ratio.

Parameter
Type
Default
Allowed Values

height

integer

0

Any positive integer, or 0 for auto

Example:


Min Width

Defines the minimum width of the resulting image.

Parameter
Type
Default
Allowed Values

width

integer

0

Any positive integer, or 0 to disable

circle-exclamation

Example:


Min Height

Defines the minimum height of the resulting image.

Parameter
Type
Default
Allowed Values

height

integer

0

Any positive integer, or 0 to disable

circle-exclamation

Example:


Enlarge

Controls whether smoxy will enlarge images that are smaller than the target dimensions.

Parameter
Type
Default
Allowed Values

enlarge

boolean

false

1, t, true to enable; 0, f, false to disable

By default, if the source image is smaller than the requested size, smoxy will not upscale it. Enable this option if you need the image to always match the requested dimensions.

Example:


Extend

When enabled, if the resized image is smaller than the target dimensions, smoxy pads the canvas to match. The padded area is filled with the background color.

Parameter
Type
Default
Allowed Values

extend

boolean

false

1, t, true to enable

gravity

string

ce:0:0

Any gravity value except sm

Example:


Extend Aspect Ratio

When enabled, extends the image canvas to match the requested aspect ratio by adding background padding.

Parameter
Type
Default
Allowed Values

extend

boolean

false

1, t, true to enable

gravity

string

ce:0:0

Any gravity value except sm

Example:


Zoom

Multiplies the image dimensions by the given factor(s). Can be combined with w and h — smoxy first calculates the size from width/height, then multiplies by the zoom factor.

Parameter
Type
Default
Allowed Values

zoom_x_y

float

1

Any value > 0 (uniform for both axes)

zoom_x

float

1

Any value > 0

zoom_y

float

1

Any value > 0

circle-info

Note: Unlike dpr, the zoom option does not affect gravity offsets, watermark offsets, or padding values.

Examples:


DPR (Device Pixel Ratio)

Multiplies image dimensions by the given factor for HiDPI (Retina) displays.

Parameter
Type
Default
Allowed Values

dpr

float

1

Any value > 0

circle-info

Note: Unlike zoom, the dpr option does affect gravity offsets, watermark offsets, and padding values. This ensures that the resulting image structure remains consistent with and without dpr applied.

Example:


Gravity

Controls where smoxy focuses when cropping parts of the image (used by fill resizing, crop, and extend).

Parameter
Type
Default
Allowed Values

type

string

ce

See table below

x_offset

float

0

Absolute pixels (≥ 1) or relative (< 1)

y_offset

float

0

Absolute pixels (≥ 1) or relative (< 1)

Gravity types

Value
Position

ce

Center (default)

no

North — top edge

so

South — bottom edge

ea

East — right edge

we

West — left edge

noea

North-east — top-right corner

nowe

North-west — top-left corner

soea

South-east — bottom-right corner

sowe

South-west — bottom-left corner

Special gravity types

Value
Description

sm

Smart gravity — automatically detects the most "interesting" section of the image and uses it as the center. Offsets are not applicable.

fp:%x:%y

Focus point — x and y are floats between 0 and 1 that define the center of the resulting image. 0:0 is top-left, 1:1 is bottom-right.

Examples:

Rewrite rule example — smart cropping thumbnails:

Regex: ^/smart/(\d+)x(\d+)/(.*) Target: /_sx/img/_/rs:fill:$1:$2/g:sm/q:80/plain/$3


Crop

Crops the image to specific dimensions before resizing. This is useful when you want to extract a specific area from the source image.

Parameter
Type
Default
Allowed Values

width

float

required

Absolute pixels (≥ 1) or relative (0–1). 0 = full source width

height

float

required

Absolute pixels (≥ 1) or relative (0–1). 0 = full source height

gravity

string

uses gravity option

Any gravity value

Examples:


Trim

Removes surrounding background pixels that are similar to a target color. If no color is specified, smoxy auto-detects the background color.

Parameter
Type
Default
Allowed Values

threshold

float

required

Color similarity tolerance (any positive number)

color

hex string

auto-detected

6-character hex color without # (e.g., ffffff). Use FF00FF for transparent backgrounds

equal_hor

boolean

false

1, t, true — trim equal amounts from left and right

equal_ver

boolean

false

1, t, true — trim equal amounts from top and bottom

circle-exclamation
circle-info

Tip: If you know the background color of your images, setting it explicitly via the color parameter saves resources because smoxy won't need to auto-detect it.

Examples:

Last updated

Was this helpful?