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 => "#2b2bd5"
3 => "#5d5da9"
4 => "#4c4c90"
5 => "#040204"
6 => "#2b4972"
7 => "#1f3451"
8 => "#162f46"
9 => "#44447e"
10 => "#424e84"
11 => "#365d88"
12 => "#435186"
13 => "#465187"
14 => "#455084"
15 => "#444f81"
16 => "#424e7f"
17 => "#424d7d"
18 => "#31397b"
19 => "#3a4372"
]