Skip to main content
Version: V3 (Ignition 8.3)

tamaki.mes.utils.getReadableTextColor

Description

Determines whether black or white text is more readable against a given hex background colour, using the perceived-brightness (YIQ) formula. Accepts a 3- or 6-digit hex string, with or without a leading #. Returns "#000000" (black) for bright backgrounds and "#FFFFFF" (white) for dark backgrounds.

Raises a ValueError if the hex string is not 3 or 6 characters long or contains invalid hex characters.

Syntax

tamaki.mes.utils.getReadableTextColor(hex_color)

Parameters

ParameterTypeNullableDescription
hex_colorStringFalseA hex colour string (for example "#FFFFFF", "000", "ff0000").

Returns

A String: "#000000" (black) or "#FFFFFF" (white).

Code Examples

# In a binding script transform: pick a readable text colour for a background hex
return tamaki.mes.utils.getReadableTextColor(value)
# e.g. "#1d4ed8" -> "#FFFFFF"