Support

Account

Home Forums Front-end Issues Convert HEX value to HSV Reply To: Convert HEX value to HSV

  • No problem at all.

    I use this part of the code to convert HEX to RGB.

    function getsub_acf_rgb($field, $id) {
    	if ( function_exists('get_sub_field') ) {
    	$hexx = get_sub_field($field, $id);
    	// extra sanity check that we're dealing with the hex flatuicolorpicker
    	// in #NNNNNN format that ACF/WordPress/Iris colorpicker returns
    	if (strlen($hexx) == 7 && substr($hexx,0,1) == '#') {
    	$rr = hexdec(substr($hexx,1,2));
    	$gg = hexdec(substr($hexx,3,2));
    	$bb = hexdec(substr($hexx,5,2));
    	return $rr . ', ' . $gg . ', ' . $bb;
    	}
    	else {
    	// provide a default in an emergency
    	return "128,128,128" ;
    	}
    	}
    	}
    
    	function acsf_rgb($field, $id) {
    	echo getsub_acf_rgb($field, $id);
    	}
    
    function hex2rgb($hex) {
    	$color = str_replace('#','',$hex);
    	$rgb = array(
    	   'r' => hexdec(substr($color,0,2)),
    	   'g' => hexdec(substr($color,2,2)),
    	   'b' => hexdec(substr($color,4,2)),
    	);
    	return $rgb;
     }

    but I wonder how I can pass the value of RGB to HSV
    referral link https://stackoverflow.com/questions/1773698/rgb-to-hsv-in-php?answertab=votes#tab-top