示例#1
0
function find_in_file($colorfile)
{
    global $hex, $r, $g, $b;
    $nmatches = 0;
    $dist = 255 * sqrt(3.0);
    # start with longest possible distance
    $fp = fopen($colorfile, 'r');
    if ($fp) {
        while (!feof($fp)) {
            $line = fgets($fp);
            if ($line[0] != '!') {
                list($r1, $g1, $b1, $name) = sscanf($line, "%d %d %d %s");
                if ($r1 == $r && $g1 == $g && $b1 == $b) {
                    print colorline($r1, $g1, $b1, $name);
                    ++$nmatches;
                    $dist == 0;
                }
                if ($nmatches == 0) {
                    # if no exact match yet, see if it's closer than what
                    # we've seen before.
                    $newdist = sqrt(pow($r - $r1, 2) + pow($g - $g1, 2) + pow($b - $b1, 2));
                    if ($newdist == $dist) {
                        $matches = $matches . colorline($r1, $g1, $b1, $name);
                    } else {
                        if ($newdist < $dist) {
                            $dist = $newdist;
                            $matches = colorline($r1, $g1, $b1, $name);
                        }
                    }
                }
            }
        }
        fclose($fp);
        if ($nmatches == 0) {
            print "<tr>";
            print "<td colspan=2>No exact match found for ({$r} {$g} {$b})\n<td>";
            print colorswatch($r, $g, $b);
            print "<tr><th colspan=3>Closest matches:";
            print $matches;
        }
    }
}
示例#2
0
$ps = PS_new();
if (0 > PS_open_file($ps, "spotcolor.ps")) {
    printf("Cannot open PostScript file\n");
    exit(1);
}
PS_set_parameter($ps, "warning", "true");
PS_set_info($ps, "Creator", __FILE__);
PS_set_info($ps, "Author", "Uwe Steinmann");
PS_set_info($ps, "Title", "Spotcolor demonstration");
PS_set_info($ps, "Keywords", "Spot color");
for ($i = 0; $i < 5; $i++) {
    PS_setcolor($ps, "fill", $spotcolors[$i]["colorspace"], $spotcolors[$i]["c1"], $spotcolors[$i]["c2"], $spotcolors[$i]["c3"], $spotcolors[$i]["c4"]);
    $spotcolors[$i]["id"] = PS_makespotcolor($ps, $spotcolors[$i]["name"], 0);
}
PS_begin_page($ps, 596, 842);
footer($ps, "");
$psfont = PS_findfont($ps, "Helvetica", "", 0);
PS_setfont($ps, $psfont, 7.0);
for ($i = 1; $i <= 10; $i++) {
    $buffer = sprintf("%d %%", $i * 10);
    PS_show_xy($ps, $buffer, 60, 55 + $i * 65);
}
colorline($ps, 100.0, $spotcolors[0]);
colorline($ps, 190.0, $spotcolors[1]);
colorline($ps, 280.0, $spotcolors[2]);
colorline($ps, 370.0, $spotcolors[3]);
colorline($ps, 460.0, $spotcolors[4]);
PS_end_page($ps);
PS_close($ps);
PS_delete($ps);
exit(0);