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
Param | Units | Description |
---|---|---|
color | Color | Indicates what color to trim off, or auto for the top-left pixel's color. |
threshold | Number | An 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
orcf23a5
). - 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 usage | Description |
---|---|
?trim-color=0,0,0 | Trim off a black background |
?trim-color=255,255,255,0.5 | Trim off a white background with 0.5 transparency |
?trim-color=FFFFFF,t0.3 | Trim off a white background with a threshold of 0.3 |
?trim-color=auto | Auto detect the color to trim by looking at the top left most pixel |
?trim-color=0,0,0,0 | Trim off an entirely transparent background |