trim-color

Identify a rectangular border based on specified or auto-detected color and remove this border from the edges of an image.

IMPORTANT: Trim by color currently only works for non-GIF input images. It is applied first, before any other transformation. Trims resulting in 0x0 images return an error.

Syntax

trim-color={color}
trim-color={color},t{threshold}

Sub-parameters

ParamUnitsDescription
colorColorIndicates what color to trim off, or auto for the top-left pixel's color.
thresholdNumberAn optional number between 0 and 1 indicating how different a color can be from the given trim color and still be trimmed. This can be used if the background that is being trimmed is not uniform (all one color). Setting it to 1 will trim everything, as 1 is the largest possible color difference.

color may be one of:

  • Hex RGB value: Both 3- and 6-digit values are acceptable (e.g., a22 or cf23a5).
  • Decimal RGB: RGB values between 0 and 255. Comma-delimited (e.g., 255,0,0).
  • Decimal RGB with alpha: RGBA colors include an additional value for alpha (transparency), which ranges from 0 for fully transparent to 1 for fully opaque. Comma-delimited (e.g., 255,255,255,0.5).

Examples

Example usageDescription
?trim-color=0,0,0Trim off a black background
?trim-color=255,255,255,0.5Trim off a white background with 0.5 transparency
?trim-color=FFFFFF,t0.3Trim off a white background with a threshold of 0.3
?trim-color=autoAuto detect the color to trim by looking at the top left most pixel
?trim-color=0,0,0,0Trim off an entirely transparent background

See also