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; }