Beispiel #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);
    }
}
Beispiel #2
0
if (!$w->read($w->cache() . "/{$hexraw}.png")) {
    $img_rgba = array(round($r * 255), round($g * 255), round($b * 255), round(abs($a - 1) * 127));
    $img = imagecreatefrompng('checker.png');
    $color = imagecolorallocatealpha($img, $img_rgba[0], $img_rgba[1], $img_rgba[2], $img_rgba[3]);
    imagefilledrectangle($img, 8, 8, 120, 120, $color);
    imagepng($img, $w->cache() . "/{$hexraw}.png");
    imagedestroy($img);
}
if ($a == 1) {
    $a = false;
}
$hex = tohex($r, $g, $b, $a);
//$hexraw = tohexraw($r,$g,$b,$a);
$hsl = tohsl($r, $g, $b, $a);
$name = toname(tohexraw($r, $g, $b));
$rgb = torgb($r, $g, $b, $a);
$rgb_pcnt = torgb_pcnt($r, $g, $b, $a);
$modes = array('hex' => $hex, 'hsl' => $hsl, 'name' => $name, 'rgb' => $rgb, 'rgb_pcnt' => $rgb_pcnt);
if (!$a) {
    $description = array('hex' => 'Hexadecimal format', 'hsl' => 'HSL format', 'name' => 'CSS3 named color', 'rgb' => 'RGB format', 'rgb_pcnt' => 'RGB percent format');
} else {
    $description = array('hex' => 'Hexadecimal format', 'hsl' => 'HSLA format', 'name' => 'CSS3 named color', 'rgb' => 'RGBA format', 'rgb_pcnt' => 'RGBA percent format');
}
foreach ($modes as $this_mode => $result) {
    if ($result == false) {
        continue;
    }
    $w->result("tylereich.colors {$mode} to {$this_mode}", $result, $result, $description[$this_mode], $w->cache() . "/{$hexraw}.png", 'yes');
}
echo $w->toxml();
function rgb($r = 0, $g = 0, $b = 0, $a = null)