Exemplo n.º 1
0
 /**
  * @param Imagine\Image\ImageInterface $image
  *
  * @return array
  */
 private function normalize(ImageInterface $image)
 {
     $step = (int) round(255 / $this->buckets);
     $red = $green = $blue = $alpha = array();
     for ($i = 1; $i <= $this->buckets; $i++) {
         $range = new Range(($i - 1) * $step, $i * $step);
         $red[] = new Bucket($range);
         $green[] = new Bucket($range);
         $blue[] = new Bucket($range);
         $alpha[] = new Bucket($range);
     }
     foreach ($image->histogram() as $color) {
         foreach ($red as $bucket) {
             $bucket->add($color->getRed());
         }
         foreach ($green as $bucket) {
             $bucket->add($color->getGreen());
         }
         foreach ($blue as $bucket) {
             $bucket->add($color->getBlue());
         }
         foreach ($alpha as $bucket) {
             $bucket->add($color->getAlpha());
         }
     }
     $total = $image->getSize()->square();
     $callback = function (Bucket $bucket) use($total) {
         return count($bucket) / $total;
     };
     return array(array_map($callback, $red), array_map($callback, $green), array_map($callback, $blue), array_map($callback, $alpha));
 }