ColorQ

ColorQ[color]

yields True if color is a valid color directive and False otherwise.

Details

  • ColorQ tests whether an expression is a valid color that can be used for styling graphics primitives or used with images as padding, background and more.
  • ColorQ returns True for any valid color directive specified in any of the following color spaces:
  • GrayLevelgray level specifying the brightness
    RGBColorstandard sRGB
    CMYKColorCMYK
    Huehue, saturation, brightness
    XYZColorCIE 1931
    LABColorCIE 1976
    LCHColorCIE
    LUVColorCIE 1976

Examples

open allclose all

Basic Examples  (2)

A valid color:

An expression with a color directive head that is not a valid color:

Scope  (2)

A valid RGBColor:

A valid RGBColor with transparency:

Validate an array of color directives:

Generalizations & Extensions  (1)

ColorQ works on expressions where color components are specified as a list:

Applications  (2)

Select colors from a list:

Define a function with custom behavior on colors and images:

Test the function on an image:

Test the function on a list of colors:

The function is unevaluated on other kinds of inputs:

Possible Issues  (1)

Unevaluated expressions that correspond to valid colors still give True:

However, if the expression is not yet a valid color, ColorQ will not evaluate it:

This is also true for expressions that need an evaluation to be marked as numerical:

Compare with the results from RealValuedNumberQ:

Wolfram Research (2014), ColorQ, Wolfram Language function, https://reference.wolfram.com/language/ref/ColorQ.html.

Text

Wolfram Research (2014), ColorQ, Wolfram Language function, https://reference.wolfram.com/language/ref/ColorQ.html.

CMS

Wolfram Language. 2014. "ColorQ." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/ColorQ.html.

APA

Wolfram Language. (2014). ColorQ. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ColorQ.html

BibTeX

@misc{reference.wolfram_2024_colorq, author="Wolfram Research", title="{ColorQ}", year="2014", howpublished="\url{https://reference.wolfram.com/language/ref/ColorQ.html}", note=[Accessed: 21-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_colorq, organization={Wolfram Research}, title={ColorQ}, year={2014}, url={https://reference.wolfram.com/language/ref/ColorQ.html}, note=[Accessed: 21-November-2024 ]}