Example #1
0
function format($mode = 'rgb', $rgba, $alpha = false, $name = false)
{
    if (!$rgba) {
        return false;
    }
    $r = $rgba['r'];
    $g = $rgba['g'];
    $b = $rgba['b'];
    $a = $rgba['a'];
    if ($alpha) {
        switch ($mode) {
            case 'hex':
                return tohex($r, $g, $b, $a);
            case 'hsl':
                return tohsl($r, $g, $b, $a);
            case 'rgb':
                return torgb($r, $g, $b, $a);
            case 'rgb_pcnt':
                return torgb_pcnt($r, $g, $b, $a);
            case 'name':
                return torgb($r, $g, $b, $a);
        }
    }
    switch ($mode) {
        case 'hex':
            return tohex($r, $g, $b);
        case 'hsl':
            return tohsl($r, $g, $b);
        case 'rgb':
            return torgb($r, $g, $b);
        case 'rgb_pcnt':
            return torgb_pcnt($r, $g, $b);
        case 'name':
            if ($name) {
                $colorName = toname(tohexraw($r, $g, $b));
                if ($colorName !== false) {
                    return $colorName;
                }
            }
            return torgb($r, $g, $b);
    }
}
Example #2
0
function tohex($r, $g, $b, $a = false)
{
    $hex = tohexraw($r, $g, $b, $a);
    return "#{$hex}";
}