Theo van der Sluijs
Jul 26 · 2 min read
Photo by Harry Quan on Unsplash

Get colors from image with python is not very difficult. You want to have all the colors from an image? Or maybe multiple images? You can open Photoshop, or like me Pixelmator, but getting all the colors with the eyedropper tool can be a lot of work. So why not use a “get colors from images” python script.

Getting colors from image

When you design websites or want to create a style for a new company you are mostly to start with colors. Now when you want to work from a certain image you really like or a pre-made logo, you might want to have all the colors from that image or logo.

You can make use of an eyedropper that can be found in an image-editing software, like Photoshop, Lightroom or Pixelmator. But when a image has many colors, you might end up spending your entire day clicking to get out all the colors.

An eyedropper is a tool found in many image editing programs that let you click on a point in the image to identify and select its color.

RGB and HEX colors

Now getting out these colors might take you a long time, but getting the RGB and HEX value can also be a lot of work.

More and more both RGB and HEX are being used within CSS / SCSS / SASS and LESS for creating websites. And as I was creating this site, and the API Python version of it it took me quite some time to get all the colors out of the logo’s.

The RGB color model is an additive color model in which red, green and blue light are added together in various ways to reproduce a broad array of colors.

Both HEX and RGB are used to define colors.

A hex triplet is a six-digit, three-byte hexadecimal number used in HTML, CSS, SVG, and other computing applications to represent colors.

Create color python script

Now I do not like repetitive work and clicking within an image to get out all the colors really looks a lot to me like repetitive work.

So I created this small color extracting script. It shows you per image all the different colors with hex and GRB values in a terminal.

purepython

Scribbles of code in Python. A new Medium publication about Python coding and other Tech.

Theo van der Sluijs

Written by

Nerd Herder ☆ Scrum Master ☆ Disruptor ☆ Python Lover (Code & Efteling) ☆ Dad ☆ Husband ☆ Zookeeper ☆ CycloCross biker ☆ Blogger ☆ Dutch

purepython

Scribbles of code in Python. A new Medium publication about Python coding and other Tech.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade