W3cubDocs

/WordPress

WP_Duotone::colord_hsva_to_rgba( array $hsva ): array

Converts an HSVA array to RGBA.

Description

Direct port of colord’s hsvaToRgba function.

Parameters

$hsvaarrayrequired
The HSVA array to convert.

Return

array The RGBA array.

Source

private static function colord_hsva_to_rgba( $hsva ) {
	$h = ( $hsva['h'] / 360 ) * 6;
	$s = $hsva['s'] / 100;
	$v = $hsva['v'] / 100;
	$a = $hsva['a'];

	$hh     = floor( $h );
	$b      = $v * ( 1 - $s );
	$c      = $v * ( 1 - ( $h - $hh ) * $s );
	$d      = $v * ( 1 - ( 1 - $h + $hh ) * $s );
	$module = $hh % 6;

	return array(
		'r' => array( $v, $c, $b, $b, $d, $v )[ $module ] * 255,
		'g' => array( $d, $v, $v, $c, $b, $b )[ $module ] * 255,
		'b' => array( $b, $b, $d, $v, $v, $c )[ $module ] * 255,
		'a' => $a,
	);
}

Changelog

Version Description
6.3.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_duotone/colord_hsva_to_rgba