How to install ColorThief in a NodeJS project?

ColorThief is an incredibly cool library that not only gives you dominant color of a given image but also generates a color palette out of it. However, trying to make it work in a NodeJS project can become devilishly hard because of its dependencies which go beyond the realm of NPM. Here I’m sharing the steps I went through, so you don’t have to repeat the struggle. Note that my steps are for OSX, so you’ll have to translate them yourself if you’re on a different platform.

1. Make sure you’ve Python installed in your system. Then find out if you’ve python2 under /usr/bin directory. If not, run this command:

sudo ln -s /usr/bin/python2.6 /usr/bin/python2

Don’t forget to change python2.6 if you’ve some other version installed.

2. Install jhbuild into your system. Here are the commands you need to run in your terminal for installation:

git clone git://
cd jhbuild
make install
echo 'PATH=$PATH:~/.local/bin' >> ~/.bashrc

3. Install gtk+. First, save this script on your system and run it in terminal. Then run these commands in the same order:

jhbuild bootstrap
jhbuild build meta-gtk-osx-bootstrap
jhbuild build

4. Make sure you’ve wget installed in your system.

5. Install canvas by running this command in your terminal:

wget -O - | sh

That’s it. Now “npm install color-thief” should work on your machine. Let me know if these steps worked for you or if you found an easier way to do the job.

Published by

Umar Ashfaq

Umar Ashfaq is a full-stack web developer. His core strength is building neat UIs with JavaScript on web but he also enjoys server side Java, NodeJS and Objective C. Follow him on twitter @umarashfaq87

Leave a Reply

Your email address will not be published. Required fields are marked *