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://git.gnome.org/jhbuild cd jhbuild ./autogen.sh make make install PATH=$PATH:~/.local/bin 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:
sh gtk-osx-build-setup.sh 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 https://raw.githubusercontent.com/LearnBoost/node-canvas/master/install -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.