wc_hex_is_light( mixed $color )

Determine whether a hex color is light.


Description Description


Parameters Parameters

$color

(Required) Color.


Top ↑

Return Return

(bool) True if a light color.


Top ↑

Source Source

File: includes/wc-formatting-functions.php

	function wc_hex_is_light( $color ) {
		$hex = str_replace( '#', '', $color );

		$c_r = hexdec( substr( $hex, 0, 2 ) );
		$c_g = hexdec( substr( $hex, 2, 2 ) );
		$c_b = hexdec( substr( $hex, 4, 2 ) );

		$brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;

		return $brightness > 155;
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.