Iromeku

November 02, 2019

I wrote a Python port of this Stack Over­flow answer, which is a way of extract­ing a colour palette from an image.

I had pre­vi­ous­ly used a JavaScript port of the same logic for a site I built some years ago, but decid­ed I could prob­a­bly write some­thing clean­er and learn some new things in the process.

I was my first time pub­lish­ing a pack­age to PyPI, so I had to learn about how to do that. Also real­ized that for how stan­dard­ized the lan­guage and the stan­dard library is, the pub­lish­ing and test­ing work­flows remain woe­ful­ly con­fus­ing.

I also had to figure out how to type hint a library that is expect­ed to work in Python 2.7+ and Python 3.5+ (hint: use com­ment-based syntax), as well as avoid­ing import­ing the typing library during run­time.

It only sup­ports get­ting the dom­i­nant colour right now, but I’ll be work­ing on being able to fetch com­pli­men­ta­ry colours, and also other sam­pling strate­gies to speed up the algo­rithm (e.g. only using border pixels, random sam­pling, etc).

Find the code here.