Skip to content

Iromeku

Posted on:November 2, 2019

I wrote a Python port of this Stack Overflow answer, which is a way of extracting a colour palette from an image.

I had previously used a JavaScript port of the same logic for a site I built some years ago, but decided I could probably write something cleaner and learn some new things in the process.

I was my first time publishing a package to PyPI, so I had to learn about how to do that. Also realized that for how standardized the language and the standard library is, the publishing and testing workflows remain woefully confusing.

I also had to figure out how to type hint a library that is expected to work in Python 2.7+ and Python 3.5+ (hint: use comment-based syntax), as well as avoiding importing the typing library during runtime.

It only supports getting the dominant colour right now, but I’ll be working on being able to fetch complimentary colours, and also other sampling strategies to speed up the algorithm (e.g. only using border pixels, random sampling, etc).

Find the code here.