For the complete documentation index, see llms.txt. This page is also available as Markdown.

Trim

Image trimming

Removes any single-color padding around the image if present.

The parameter does not specify the amount of border or frame to trim but rather how aggressive the trim algorithm should be. A bigger value of the parameter (e.g. 25) will trim rather more than not enough. Typical values are between 0 and 10.

This allows you to use the same parameter values for all your images.

trim=X

If the image is resized with the width and/or height commands, the resizing is performed after the border (if present) is trimmed.

Trim gravity

When gravity=trim is set alongside trim=X (for the Crop, Fit or Cropfit operations), the focal point is defined depending on the trim result:

  • When the image is trimmed on all sides, gravity is set to center;

  • When no trim has been performed, gravity is set to smart;

  • If the image has been trimmed on some edges only, the gravity is set to:

    • fit operation - gravity is set to the edges opposite of the trimmed ones so that the canvas is extended only on the trimmed sides;

    • crop operation - gravity is set to the trimmed edges so that the image is not cropped anymore on the trimmed edges.

Whitespace trim

By default, the trim operation removes any solid color regions at the edges. If you prefer to only trim out white (and near-white) and transparent regions while preserving other solid colors, you can add the whites instruction to the trim. The intensity parameter remains the same.

trim=whites,X

Examples

Preview
Syntax

Original image: /docs/sofa.jpg?w=400

Original image: /docs/darkside.jpg

Wrongly trimmed image: /docs/darkside.jpg?trim=1

Trim corrected with "only whites": /docs/darkside.jpg?trim=whites,1

Last updated