Exemplo n.º 1
0
Arquivo: lib.php Projeto: vench/esee
/**
* Получить путь картинки
*/
function getDirectionPath($filename)
{
    $im = strpos($filename, 'png') !== false ? imagecreatefrompng($filename) : imagecreatefromjpeg($filename);
    $width = imagesx($im);
    $height = imagesy($im);
    $directions = [];
    $point = null;
    $points = [];
    for ($y = 0; $y < $height; $y++) {
        for ($x = 0; $x < $width; $x++) {
            $a1 = isDark(imagecolorat($im, $x, $y));
            $a2 = $width == $x + 1 ? $a1 : isDark(imagecolorat($im, $x + 1, $y));
            $a3 = $height == $y + 1 ? $a1 : isDark(imagecolorat($im, $x, $y + 1));
            if ($a1 != $a2 || $a1 != $a3) {
                if (VIEW_DEBAG) {
                    echo 1;
                }
                $points[] = [$x, $y];
            } else {
                if (VIEW_DEBAG) {
                    echo '.';
                }
            }
        }
        if (VIEW_DEBAG) {
            echo "\n";
        }
    }
    imagedestroy($im);
    usort($points, function ($a, $b) {
        $d = sqrt(pow(abs($a[0] - $b[0]), 2) + pow(abs($a[1] - $b[1]), 2));
        return $a[1] > $b[1] ? -1 : 1;
    });
    $a = null;
    while (sizeof($points) > 0) {
        if (is_null($a)) {
            $a = array_shift($points);
        }
        $min = null;
        foreach ($points as $k => $b) {
            $d = sqrt(pow(abs($a[0] - $b[0]), 2) + pow(abs($a[1] - $b[1]), 2));
            if (is_null($min) || $min[0] > $d) {
                $min = [$d, $b, $k];
            }
        }
        unset($points[$min[2]]);
        $x = $min[1][0];
        $y = $min[1][1];
        $d = 0;
        if ($a[0] < $x && $a[1] < $y) {
            $d = 1;
            //'BR';
        } else {
            if ($a[0] == $x && $a[1] < $y) {
                $d = 2;
                //'B';
            } else {
                if ($a[0] < $x && $a[1] == $y) {
                    $d = 3;
                    //'R';
                } else {
                    if ($a[0] < $x && $a[1] > $y) {
                        $d = 4;
                        //'TR';
                    } else {
                        if ($a[0] == $x && $a[1] > $y) {
                            $d = 5;
                            //'T';
                        } else {
                            if ($a[0] > $x && $a[1] > $y) {
                                $d = 6;
                                //'TL';
                            } else {
                                if ($a[0] > $x && $a[1] == $y) {
                                    $d = 7;
                                    //'L';
                                } else {
                                    if ($a[0] > $x && $a[1] < $y) {
                                        $d = 8;
                                        //'BL';
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        if (sizeof($directions) == 0 || $directions[sizeof($directions) - 1] != $d) {
            $directions[] = $d;
        }
        $a = $min[1];
    }
    return join('', $directions);
}
Exemplo n.º 2
0
Arquivo: cl1.php Projeto: vench/esee
{
    //return $rgb == 0;// var_dump($rgb);
    $r = $rgb >> 16 & 0xff;
    $g = $rgb >> 8 & 0xff;
    $b = $rgb & 0xff;
    // var_dump($r, $g, $b);
    return $r < 127 && $g < 127 && $b < 127;
    // == 0;
}
$directions = [];
$point = null;
for ($y = 0; $y < $height; $y++) {
    for ($x = 0; $x < $width; $x++) {
        $a1 = isDark(imagecolorat($im, $x, $y));
        $a2 = $width == $x + 1 ? $a1 : isDark(imagecolorat($im, $x + 1, $y));
        $a3 = $height == $y + 1 ? $a1 : isDark(imagecolorat($im, $x, $y + 1));
        if ($a1 != $a2 || $a1 != $a3) {
            echo 1;
            if (!is_null($point)) {
                $d = '';
                if ($point[0] < $x && $point[1] < $y) {
                    $d = 'юго-восток';
                } else {
                    if ($point[0] == $x && $point[1] < $y) {
                        $d = 'юг';
                    } else {
                        if ($point[0] < $x && $point[1] == $y) {
                            $d = 'восток';
                        } else {
                            if ($point[0] < $x && $point[1] > $y) {
                                $d = 'северо-восток';