Are there any alternative libraries or methods that can be used to list all colors of an image in PHP, apart from GD?

The GD library in PHP does not have a built-in function to list all colors of an image. One alternative method is to use the Imagick library, which provides more advanced image processing capabilities, including the ability to get a list of unique colors from an image.

// Load the image using Imagick
$image = new Imagick('image.jpg');

// Get the image histogram to retrieve unique colors
$histogram = $image->getImageHistogram();

$colors = [];

// Loop through the histogram to extract unique colors
foreach ($histogram as $pixel) {
    $color = $pixel->getColor();
    $rgb = "rgb({$color['r']}, {$color['g']}, {$color['b']})";
    
    // Add the RGB value to the colors array
    $colors[] = $rgb;
}

// Display the list of unique colors
print_r(array_unique($colors));