示例#1
0
function color_to_name($color)
{
    if (!isset($GLOBALS['color_names'])) {
        global $color_names;
        $color_names = file(dirname(__FILE__) . '/color_names.json');
    }
    $color = strtoupper($color);
    $r = hexdec(substr($color, 0, 2));
    $g = hexdec(substr($color, 2, 2));
    $b = hexdec(substr($color, 4, 2));
    $hsl = hsl($color);
    $h = $hsl[0];
    $s = $hsl[1];
    $l = $hsl[2];
    $ndf1 = 0;
    $ndf2 = 0;
    $ndf = 0;
    $cl = -1;
    $df = -1;
    $count = count($GLOBALS['color_names']);
    for ($i = 0; $i < $count; $i++) {
        if ($color == $GLOBALS['color_names'][$i]) {
            return $GLOBALS['color_names'][$i];
        }
        $name_r = hexdec(substr($GLOBALS['color_names'][$i], 0, 2));
        $name_g = hexdec(substr($GLOBALS['color_names'][$i], 2, 2));
        $name_b = hexdec(substr($GLOBALS['color_names'][$i], 4, 2));
        $name_hsl = hsl($GLOBALS['color_names'][$i]);
        $name_h = $name_hsl[0];
        $name_s = $name_hsl[1];
        $name_l = $name_hsl[2];
        $ndf1 = pow($r - $name_r, 2) + pow($g - $name_g, 2) + pow($b - $name_b, 2);
        $ndf2 = abs(pow($h - $name_h, 2)) + pow($s - $name_s, 2) + abs(pow($l - $name_l, 2));
        $ndf = $ndf1 + $ndf2 * 2;
        if ($df < 0 || $df > $ndf) {
            $df = $ndf;
            $cl = $i;
        }
    }
    return $cl < 0 ? array("#000000", "Invalid Color: " . $color . '|' . $cl . '|' . $df, "#000000") : $GLOBALS['color_names'][$cl];
}
示例#2
0
function color_to_name($color)
{
    $names = file_get_contents(dirname(__FILE__) . '/color_names.json');
    $names = json_decode($names, true);
    $color = strtoupper($color);
    $r = hexdec(substr($color, 0, 2));
    $g = hexdec(substr($color, 2, 2));
    $b = hexdec(substr($color, 4, 2));
    $hsl = hsl($color);
    $h = $hsl[0];
    $s = $hsl[1];
    $l = $hsl[2];
    $ndf1 = 0;
    $ndf2 = 0;
    $ndf = 0;
    $cl = -1;
    $df = -1;
    $count = count($names);
    for ($i = 0; $i < $count; $i++) {
        if ($color == $names[$i][0]) {
            return array("#" . $names[$i][0], $names[$i][1], $names[$i][2]);
        }
        $name_r = hexdec(substr($names[$i][0], 0, 2));
        $name_g = hexdec(substr($names[$i][0], 2, 2));
        $name_b = hexdec(substr($names[$i][0], 4, 2));
        $name_hsl = hsl($names[$i][0]);
        $name_h = $name_hsl[0];
        $name_s = $name_hsl[1];
        $name_l = $name_hsl[2];
        $ndf1 = pow($r - $name_r, 2) + pow($g - $name_g, 2) + pow($b - $name_b, 2);
        $ndf2 = abs(pow($h - $name_h, 2)) + pow($s - $name_s, 2) + abs(pow($l - $name_l, 2));
        $ndf = $ndf1 + $ndf2 * 2;
        if ($df < 0 || $df > $ndf) {
            $df = $ndf;
            $cl = $i;
        }
    }
    return $cl < 0 ? array("#000000", "Invalid Color: " . $color . '|' . $cl . '|' . $df, "#000000") : array("#" . $names[$cl][0], $names[$cl][1], $names[$cl][2]);
}
示例#3
0
    noresult($mode);
    echo $w->toxml();
    return;
}
$modes = array('hex', 'hsl', 'name', 'rgb', 'rgb_pcnt');
$rgba;
$names = array('f0f8ff' => 'aliceblue', 'faebd7' => 'antiquewhite', '00ffff' => 'aqua', '7fffd4' => 'aquamarine', 'f0ffff' => 'azure', 'f5f5dc' => 'beige', 'ffe4c4' => 'bisque', '000000' => 'black', 'ffebcd' => 'blanchedalmond', '0000ff' => 'blue', '8a2be2' => 'blueviolet', 'a52a2a' => 'brown', 'deb887' => 'burlywood', 'ea7e5d' => 'burntsienna', '5f9ea0' => 'cadetblue', '7fff00' => 'chartreuse', 'd2691e' => 'chocolate', 'ff7f50' => 'coral', '6495ed' => 'cornflowerblue', 'fff8dc' => 'cornsilk', 'dc143c' => 'crimson', '00ffff' => 'cyan', '00008b' => 'darkblue', '008b8b' => 'darkcyan', 'b8860b' => 'darkgoldenrod', 'a9a9a9' => 'darkgray', '006400' => 'darkgreen', 'a9a9a9' => 'darkgrey', 'bdb76b' => 'darkkhaki', '8b008b' => 'darkmagenta', '556b2f' => 'darkolivegreen', 'ff8c00' => 'darkorange', '9932cc' => 'darkorchid', '8b0000' => 'darkred', 'e9967a' => 'darksalmon', '8fbc8f' => 'darkseagreen', '483d8b' => 'darkslateblue', '2f4f4f' => 'darkslategray', '2f4f4f' => 'darkslategrey', '00ced1' => 'darkturquoise', '9400d3' => 'darkviolet', 'ff1493' => 'deeppink', '00bfff' => 'deepskyblue', '696969' => 'dimgray', '696969' => 'dimgrey', '1e90ff' => 'dodgerblue', 'b22222' => 'firebrick', 'fffaf0' => 'floralwhite', '228b22' => 'forestgreen', 'ff00ff' => 'fuchsia', 'dcdcdc' => 'gainsboro', 'f8f8ff' => 'ghostwhite', 'ffd700' => 'gold', 'daa520' => 'goldenrod', '808080' => 'gray', '008000' => 'green', 'adff2f' => 'greenyellow', '808080' => 'grey', 'f0fff0' => 'honeydew', 'ff69b4' => 'hotpink', 'cd5c5c' => 'indianred', '4b0082' => 'indigo', 'fffff0' => 'ivory', 'f0e68c' => 'khaki', 'e6e6fa' => 'lavender', 'fff0f5' => 'lavenderblush', '7cfc00' => 'lawngreen', 'fffacd' => 'lemonchiffon', 'add8e6' => 'lightblue', 'f08080' => 'lightcoral', 'e0ffff' => 'lightcyan', 'fafad2' => 'lightgoldenrodyellow', 'd3d3d3' => 'lightgray', '90ee90' => 'lightgreen', 'd3d3d3' => 'lightgrey', 'ffb6c1' => 'lightpink', 'ffa07a' => 'lightsalmon', '20b2aa' => 'lightseagreen', '87cefa' => 'lightskyblue', '778899' => 'lightslategray', '778899' => 'lightslategrey', 'b0c4de' => 'lightsteelblue', 'ffffe0' => 'lightyellow', '00ff00' => 'lime', '32cd32' => 'limegreen', 'faf0e6' => 'linen', 'ff00ff' => 'magenta', '800000' => 'maroon', '66cdaa' => 'mediumaquamarine', '0000cd' => 'mediumblue', 'ba55d3' => 'mediumorchid', '9370db' => 'mediumpurple', '3cb371' => 'mediumseagreen', '7b68ee' => 'mediumslateblue', '00fa9a' => 'mediumspringgreen', '48d1cc' => 'mediumturquoise', 'c71585' => 'mediumvioletred', '191970' => 'midnightblue', 'f5fffa' => 'mintcream', 'ffe4e1' => 'mistyrose', 'ffe4b5' => 'moccasin', 'ffdead' => 'navajowhite', '000080' => 'navy', 'fdf5e6' => 'oldlace', '808000' => 'olive', '6b8e23' => 'olivedrab', 'ffa500' => 'orange', 'ff4500' => 'orangered', 'da70d6' => 'orchid', 'eee8aa' => 'palegoldenrod', '98fb98' => 'palegreen', 'afeeee' => 'paleturquoise', 'db7093' => 'palevioletred', 'ffefd5' => 'papayawhip', 'ffdab9' => 'peachpuff', 'cd853f' => 'peru', 'ffc0cb' => 'pink', 'dda0dd' => 'plum', 'b0e0e6' => 'powderblue', '800080' => 'purple', 'ff0000' => 'red', 'bc8f8f' => 'rosybrown', '4169e1' => 'royalblue', '8b4513' => 'saddlebrown', 'fa8072' => 'salmon', 'f4a460' => 'sandybrown', '2e8b57' => 'seagreen', 'fff5ee' => 'seashell', 'a0522d' => 'sienna', 'c0c0c0' => 'silver', '87ceeb' => 'skyblue', '6a5acd' => 'slateblue', '708090' => 'slategray', '708090' => 'slategrey', 'fffafa' => 'snow', '00ff7f' => 'springgreen', '4682b4' => 'steelblue', 'd2b48c' => 'tan', '008080' => 'teal', 'd8bfd8' => 'thistle', 'ff6347' => 'tomato', '40e0d0' => 'turquoise', 'ee82ee' => 'violet', 'f5deb3' => 'wheat', 'ffffff' => 'white', 'f5f5f5' => 'whitesmoke', 'ffff00' => 'yellow', '9acd32' => 'yellowgreen');
switch ($mode) {
    case 'hex':
        preg_match('/[0-9A-Fa-f]*/', $q, $match);
        $rgba = hex($match[0]);
        break;
    case 'hsl':
        $input = preg_replace('/[^0-9.,-]/', '', $q);
        $input = explode(',', $input);
        $rgba = hsl(array_key_exists(0, $input) ? $input[0] : null, array_key_exists(1, $input) ? $input[1] : null, array_key_exists(2, $input) ? $input[2] : null, array_key_exists(3, $input) ? $input[3] : null);
        break;
    case 'rgb':
        $input = preg_replace('/[^0-9%.,-]/', '', $q);
        $input = explode(',', $input);
        $rgba = rgb(array_key_exists(0, $input) ? $input[0] : null, array_key_exists(1, $input) ? $input[1] : null, array_key_exists(2, $input) ? $input[2] : null, array_key_exists(3, $input) ? $input[3] : null);
        break;
    case 'name':
        $input = preg_replace('/[^a-zA-Z]/', '', $q);
        if ($input) {
            $rgba = name($input);
        } else {
            noresult($mode);
            echo $w->toxml();
            return;
        }
示例#4
0
    $w->result('tylereich.colors picker', "pick|{$mode}", 'Color Picker', 'Action this item to reveal the OS X color picker', 'icon.png', 'yes');
    echo $w->toxml();
    return;
}
$modes = array('hex', 'hsl', 'name', 'rgb', 'rgb_pcnt');
$rgba;
$names = array('f0f8ff' => 'aliceblue', 'faebd7' => 'antiquewhite', '00ffff' => 'aqua', '7fffd4' => 'aquamarine', 'f0ffff' => 'azure', 'f5f5dc' => 'beige', 'ffe4c4' => 'bisque', '000000' => 'black', 'ffebcd' => 'blanchedalmond', '0000ff' => 'blue', '8a2be2' => 'blueviolet', 'a52a2a' => 'brown', 'deb887' => 'burlywood', 'ea7e5d' => 'burntsienna', '5f9ea0' => 'cadetblue', '7fff00' => 'chartreuse', 'd2691e' => 'chocolate', 'ff7f50' => 'coral', '6495ed' => 'cornflowerblue', 'fff8dc' => 'cornsilk', 'dc143c' => 'crimson', '00ffff' => 'cyan', '00008b' => 'darkblue', '008b8b' => 'darkcyan', 'b8860b' => 'darkgoldenrod', 'a9a9a9' => 'darkgray', '006400' => 'darkgreen', 'a9a9a9' => 'darkgrey', 'bdb76b' => 'darkkhaki', '8b008b' => 'darkmagenta', '556b2f' => 'darkolivegreen', 'ff8c00' => 'darkorange', '9932cc' => 'darkorchid', '8b0000' => 'darkred', 'e9967a' => 'darksalmon', '8fbc8f' => 'darkseagreen', '483d8b' => 'darkslateblue', '2f4f4f' => 'darkslategray', '2f4f4f' => 'darkslategrey', '00ced1' => 'darkturquoise', '9400d3' => 'darkviolet', 'ff1493' => 'deeppink', '00bfff' => 'deepskyblue', '696969' => 'dimgray', '696969' => 'dimgrey', '1e90ff' => 'dodgerblue', 'b22222' => 'firebrick', 'fffaf0' => 'floralwhite', '228b22' => 'forestgreen', 'ff00ff' => 'fuchsia', 'dcdcdc' => 'gainsboro', 'f8f8ff' => 'ghostwhite', 'ffd700' => 'gold', 'daa520' => 'goldenrod', '808080' => 'gray', '008000' => 'green', 'adff2f' => 'greenyellow', '808080' => 'grey', 'f0fff0' => 'honeydew', 'ff69b4' => 'hotpink', 'cd5c5c' => 'indianred', '4b0082' => 'indigo', 'fffff0' => 'ivory', 'f0e68c' => 'khaki', 'e6e6fa' => 'lavender', 'fff0f5' => 'lavenderblush', '7cfc00' => 'lawngreen', 'fffacd' => 'lemonchiffon', 'add8e6' => 'lightblue', 'f08080' => 'lightcoral', 'e0ffff' => 'lightcyan', 'fafad2' => 'lightgoldenrodyellow', 'd3d3d3' => 'lightgray', '90ee90' => 'lightgreen', 'd3d3d3' => 'lightgrey', 'ffb6c1' => 'lightpink', 'ffa07a' => 'lightsalmon', '20b2aa' => 'lightseagreen', '87cefa' => 'lightskyblue', '778899' => 'lightslategray', '778899' => 'lightslategrey', 'b0c4de' => 'lightsteelblue', 'ffffe0' => 'lightyellow', '00ff00' => 'lime', '32cd32' => 'limegreen', 'faf0e6' => 'linen', 'ff00ff' => 'magenta', '800000' => 'maroon', '66cdaa' => 'mediumaquamarine', '0000cd' => 'mediumblue', 'ba55d3' => 'mediumorchid', '9370db' => 'mediumpurple', '3cb371' => 'mediumseagreen', '7b68ee' => 'mediumslateblue', '00fa9a' => 'mediumspringgreen', '48d1cc' => 'mediumturquoise', 'c71585' => 'mediumvioletred', '191970' => 'midnightblue', 'f5fffa' => 'mintcream', 'ffe4e1' => 'mistyrose', 'ffe4b5' => 'moccasin', 'ffdead' => 'navajowhite', '000080' => 'navy', 'fdf5e6' => 'oldlace', '808000' => 'olive', '6b8e23' => 'olivedrab', 'ffa500' => 'orange', 'ff4500' => 'orangered', 'da70d6' => 'orchid', 'eee8aa' => 'palegoldenrod', '98fb98' => 'palegreen', 'afeeee' => 'paleturquoise', 'db7093' => 'palevioletred', 'ffefd5' => 'papayawhip', 'ffdab9' => 'peachpuff', 'cd853f' => 'peru', 'ffc0cb' => 'pink', 'dda0dd' => 'plum', 'b0e0e6' => 'powderblue', '800080' => 'purple', 'ff0000' => 'red', 'bc8f8f' => 'rosybrown', '4169e1' => 'royalblue', '8b4513' => 'saddlebrown', 'fa8072' => 'salmon', 'f4a460' => 'sandybrown', '2e8b57' => 'seagreen', 'fff5ee' => 'seashell', 'a0522d' => 'sienna', 'c0c0c0' => 'silver', '87ceeb' => 'skyblue', '6a5acd' => 'slateblue', '708090' => 'slategray', '708090' => 'slategrey', 'fffafa' => 'snow', '00ff7f' => 'springgreen', '4682b4' => 'steelblue', 'd2b48c' => 'tan', '008080' => 'teal', 'd8bfd8' => 'thistle', 'ff6347' => 'tomato', '40e0d0' => 'turquoise', 'ee82ee' => 'violet', 'f5deb3' => 'wheat', 'ffffff' => 'white', 'f5f5f5' => 'whitesmoke', 'ffff00' => 'yellow', '9acd32' => 'yellowgreen');
switch ($mode) {
    case 'hex':
        preg_match('/[0-9A-Fa-f]*/', $q, $match);
        $rgba = hex($match[0]);
        break;
    case 'hsl':
        $input = preg_replace('/[^0-9.,-]/', '', $q);
        $input = explode(',', $input);
        $rgba = hsl($input[0], $input[1], $input[2], $input[3]);
        break;
    case 'rgb':
        $input = preg_replace('/[^0-9%.,-]/', '', $q);
        $input = explode(',', $input);
        $rgba = rgb($input[0], $input[1], $input[2], $input[3]);
        break;
    case 'name':
        $input = preg_replace('/[^a-zA-Z]/', '', $q);
        if ($input) {
            $rgba = name($input);
        } else {
            $w->result('tylereich.colors picker', 'color-pick', 'Color Picker', 'Action this item to reveal the OS X color picker', 'icon.png', 'yes');
            echo $w->toxml();
            return;
        }