Support

Account

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

  • Unfortunately, your image isn’t working.

    The link you supplied was to go from RGB to HSV

    I don’t know if you can go direct from HEX to HSV, you may need to convert your HEX to RGB then to HSV – may not be 100% accurate though as going from RGB to HSV.

    So you either need to adjust your output setting of the ACF field to the RGBA array (as per my example) OR you need to add the additional step.

    
    <?php
    $rgb_hex = get_field('colour');
    list($R, $G, $B) = sscanf($rgb_hex, "#%02x%02x%02x");
    
    $hsv = RGBtoHSV($R, $G, $B);
    
    echo '<pre>';
    print_r($hsv);
    echo '</pre>';
    
    echo '<p>Red: '.$hsv[0].' Green: '.$hsv[1].' Blue: '.$hsv[2].'</p>';