public function getHotSpots()
 {
     $crawler = new Crawler($this);
     $outlines = new CrawlerOutlineCollection();
     $size = $this->image->size();
     for ($x = 0; $x < $size[0]; $x++) {
         for ($y = 0; $y < $size[1]; $y++) {
             $pixel = $this->pixel($x, $y);
             // Skip white pixels
             if ($pixel->color()->compare(ImageColor::white(), 5)) {
                 continue;
             }
             // Skip crawled areas
             if ($outlines->contains($pixel)) {
                 continue;
             }
             // Start crawling
             $outline = $crawler->crawl($x, $y);
             $outlines->push($outline);
         }
     }
     $hotspots = new ImageCollection();
     foreach ($outlines as $outline) {
         $hotspots->push($this->image->sliceByOutline($outline));
     }
     return array($hotspots, $outlines);
 }
Ejemplo n.º 2
0
 public static function black()
 {
     if (self::$black === null) {
         self::$black = self::fromInt(0x0);
     }
     return self::$black;
 }
Ejemplo n.º 3
0
 /**
  * Draws a polygon
  */
 protected function _polygon(array $points, $color, $filled = false)
 {
     if ($filled) {
         imagefilledpolygon($this->gd, $points, count($points) / 2, ImageColor::parse($color));
     } else {
         imagepolygon($this->gd, $points, count($points) / 2, ImageColor::parse($color));
     }
 }
Ejemplo n.º 4
0
 public function colorat($x, $y)
 {
     return ImageColor::fromInt(imagecolorat($this->img, $x, $y));
 }
Ejemplo n.º 5
0
 /**
  * Looks at ahead pixel and return if it's white/outside or black 
  *
  * @param  integer $pos  the position of the ahead pixel (1,2,3)
  *
  * @return boolean  
  *      
  */
 private function look($pos = 1)
 {
     $x = $this->x + $this->dir('x' . $pos);
     $y = $this->y + $this->dir('y' . $pos);
     $pixel = $this->matrix->pixel($x, $y);
     // Position is outside the matrix
     if ($pixel === null) {
         return false;
     }
     return !$pixel->color()->compare(ImageColor::white(), 5);
     // Use 5% white tolerance
 }