Getting all colors of a picture with imagine

Code
<?php

use Imagine\Gd\Imagine;
use 
Imagine\Filter\Advanced\OnPixelBased;
use 
Imagine\Image\ImageInterface;
use 
Imagine\Image\PointInterface;

$imgPath 'php_logo.png';

$imagine = new Imagine();
$image $imagine->open($imgPath);

$colorList = [];

$function = function (ImageInterface $imagePointInterface $point) use (&$colorList) {
    
$color $image->getColorAt($point);
    
$colorList[] = (string) $color;
};

$onPixelBased = new OnPixelBased($function);
$onPixelBased->apply($image);

$original base64_encode($image->get('png'));

echo 
'image:<br><img src="data:image/png;base64,' $original '">' PHP_EOL;

// a slice of all the colors:
dump(
    
array_slice(
        
array_unique($colorList),
        
0,
        
20
    
)
);
Result
image:

array:20 [
0 => "#ffffff"
1 => "#0000ff"
2 => "#0e19ea"
3 => "#474a90"
4 => "#4b5b74"
5 => "#535cc1"
6 => "#4c6c85"
7 => "#50567f"
8 => "#6c7aab"
9 => "#727ea7"
10 => "#7480a3"
11 => "#7377af"
12 => "#3335b5"
13 => "#8d91c7"
14 => "#9192ae"
15 => "#888ead"
16 => "#8c8ba3"
17 => "#9396b5"
18 => "#9fa6cb"
19 => "#a1a8d0"
]
Used Versions
PHP 7.3, Zend 3.0, Symfony 4.3, Laravel 5.8, PHPUnit 8.0, Doctrine 2.10