Color Key Contiguous
colorkey-contiguous
The colorkey-contiguous parameter limits colorkey to the background that touches the image’s border. Areas of the key color inside the subject, such as a white logo on a product shot against white, stay opaque. It has no effect without colorkey.
| Value | Result |
|---|---|
false (default) | Every pixel near the key color becomes transparent, wherever it is. |
true | Only pixels near the key color that connect to the border become transparent. |
1/0, yes/no and on/off are also accepted. It works with every way of choosing the key: a color, auto or corners.
The examples use bg to show the keyed area in a dark color.
How the Background Is Found
The key is first applied to every pixel, exactly as it is without colorkey-contiguous. The keyed area is then traced inward from the border:
- It starts from every keyed pixel on the image’s border.
- It spreads only between pixels that share an edge, never across a diagonal. A subject outline with a one-pixel diagonal break still holds, but a gap one pixel wide lets the background in.
- Pixels that were already transparent in the source carry it, so a background behind a transparent margin is still reached.
- A pixel that matches the key but is not reached keeps its original color and opacity, including its soft edge.
On animated images, each frame is traced separately, so a moving subject keeps its inside on every frame.
A background that winds back on itself many times, such as a spiral or a maze, may not be reached all the way in. The parts that are not reached stay opaque.
Cropping to the Subject
colorkey-contiguous runs before trimming, so trim=alpha crops to what is left after the key.
Large Images
With colorkey-contiguous=true, an image larger than 10000 pixels on either side is scaled down to 10000 before it is keyed, and the output can be no larger than 10000 pixels on each side. rect and relative w and h values still refer to the source image’s pixels.



