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);
 }
示例#2
0
 public function avg()
 {
     if ($this->avg === null) {
         $image = $this->resize([self::AVG_SIZE, self::AVG_SIZE]);
         $colors = array();
         for ($x = 0; $x < self::AVG_SIZE; $x++) {
             for ($y = 0; $y < self::AVG_SIZE; $y++) {
                 $color = $image->colorat($x, $y);
                 if (!$color->compare(ImageColor::white())) {
                     $colors[] = $color;
                 }
             }
         }
         $this->avg = ImageColor::avg($colors);
     }
     return $this->avg;
 }
示例#3
0
 public static function white()
 {
     if (self::$white === null) {
         self::$white = self::fromInt(0xffffff);
     }
     return self::$white;
 }
示例#4
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
 }