Get the average colour from an Image with ImageMagick in PHP

I’ve seen a few ways around the Internet on how to get the average (or “overall”) colour of an image using PHP. A lot of them have been using PHP’s gd image library and doing a bunch of manual pixel by pixel calculation, which just seems unnecessary.

I’ve always been a fan of the Imagick PHP extension which interacts with the Image Magick program, so I’ve implemented a quick function which will calculate an Image’s average colour with none of the grunt work.

This PHP code allows you easily find the average color of an entire image:

comments powered by Disqus