@Gargron I have came across this recently and it looks pretty cool: github.com/lokesh/color-thief

Haven't tested it but something like that looks pretty accurate and it has an API.