Hello,
I was originally going to include this as part of my forthcoming AdminStyleChroma module but decided to roll it out as its own module.
https://github.com/solonmedia/ImageColorThief
Please check out the readme for a deeper explanation - but the short version here for now:
This module adds two new methods to the Pageimage class, allowing you to extract the main dominant color or a palette of prevalent colors from an image.
You can use the entire image to evaluate color dominance, or you can use a select swatch from the image based on inset rectangles from the edges, blocks at each corner, or a swatch centered on the focus point if you choose to use it. You can also select the granularity of the quantization to get more accurate color results.
This is not an eyedropper algorithm - the colors are close approximates. Great if you have color schemes you'd like to coordinate with the headliner or seasonal images, or if you'd like to be able to sort a gallery of images by dominant color, etc. Looks real nice, for example if you are running a ken burns style image fade background and the images are sorted by a channel, etc.
How to sort them? Ugh that's something I haven't tackled - yet: https://www.alanzucconi.com/2015/09/30/colour-sorting/
It works on JPG, GIF, PNG and WEBP images.
It outputs RGB, HEX, RGB Integer, raw Array with R, G, B elements or an object.
Once I've got myself registered and whatnot I'll submit it to the Modules Directory.
Installs from zip for now: https://github.com/solonmedia/ImageColorThief/archive/refs/heads/main.zip
I'd consider it Beta - the underlying libraries are pretty stable but I'd like to run a few more tests on input.
Let me know if you have any questions/thoughts.