maxbrightness = $yes; return $this; } public function setcolors($yes) { $this->colors = $yes; return $this; } public function getalpha() { return $this->alpha; } public function algorithm($x, $y) { if (($y == 0 || $y == $this->image->height() - 1) || ($x == 0 || $x == $this->image->width() - 1)) return 0; $sumx = 0; $sumy = 0; for($i = -1; $i <= 1; $i++) { for($j = -1; $j <= 1; $j++) { if (self::$gx[$i + 1][$j + 1] == 0 && self::$gy[$i + 1][$j + 1] == 0) continue; $intensity = $this->image->getpixel($x + $i, $y + $j, false); $intensity = reset($intensity); $sumx += $intensity * self::$gx[$i + 1][$j + 1]; $sumy += $intensity * self::$gy[$i + 1][$j + 1]; }} $sum = sqrt(pow($sumx, 2) + pow($sumy, 2)); $alpha = atan2($sumy, $sumx) * 180 / M_PI; $alpha = round($alpha / 45) * 45; if ($alpha < 0) $alpha += 180; $alpha %= 180; if ($y == 0) $this->alpha[$x] = array(); $this->alpha[$x][$y] = $alpha; if ($sum < $this->threshold) return 0; if ($this->maxbrightness) $sum = 255; if (!$this->colors) return $sum; switch ($alpha) { case 0: return array("red" => $sum, "green" => $sum, "blue" => 0); case 45: /* red */ return array("red" => $sum, "green" => 0, "blue" => 0); case 90: /* blue */ return array("red" => 0, "green" => 0, "blue" => $sum); case 135: /* green */ return array("red" => 0, "green" => $sum, "blue" => 0); default: throw new AlgorithmException("Impossible."); } } }