class ReplaceColor extends EffectQualifier

Maps an input color and those similar to the input color to corresponding shades of a specified output color, taking luminosity and chroma into account, in order to recolor objects in your image in a natural way.

More highly saturated input colors usually give the best results. It is recommended to avoid input colors approaching white, black, or gray.

Learn more: Replace colors example

Methods

__construct(string|ColorValue $toColor, int $tolerance = null, string|ColorValue $fromColor = null)

ReplaceColor constructor.

toColor(string|ColorValue $to)

Sets the target output color.

tolerance(int $tolerance)

Sets the tolerance threshold.

fromColor(string|ColorValue $fromColor)

Sets the base input color to map.

Details

__construct(string|ColorValue $toColor, int $tolerance = null, string|ColorValue $fromColor = null)

ReplaceColor constructor.

Parameters

Name Type Description
$toColor string|ColorValue The HTML name or RGB/A hex code of the target output color.
$tolerance int The tolerance threshold (a radius in the LAB color space) from the input color.
$fromColor string|ColorValue The HTML name or RGB/A hex code of the base input color to map.

ReplaceColor toColor(string|ColorValue $to)

Sets the target output color.

Parameters

Name Type Description
$to string|ColorValue The HTML name or RGB/A hex code of the target output color.

Return Value

ReplaceColor

ReplaceColor tolerance(int $tolerance)

Sets the tolerance threshold.

Parameters

Name Type Description
$tolerance int The tolerance threshold (a radius in the LAB color space) from the input color, representing the span of colors that should be replaced with a correspondingly adjusted version of the target output color. Larger values result in replacing more colors within the image. The more saturated the original input color, the more a change in value will impact the result.

Return Value

ReplaceColor

ReplaceColor fromColor(string|ColorValue $fromColor)

Sets the base input color to map.

Parameters

Name Type Description
$fromColor string|ColorValue The HTML name or RGB/A hex code of the base input color to map.

Return Value

ReplaceColor