Skip to content

Instantly share code, notes, and snippets.

View ndrhzn's full-sized avatar

Andrii Hazin ndrhzn

View GitHub Profile
@ndrhzn
ndrhzn / getcolor.py
Last active December 10, 2017 22:16 — forked from zollinger/getcolor.py
Simple way to get dominant colors from an image in Python
import Image, ImageDraw
def get_colors(infile, outfile, numcolors=10, swatchsize=20, resize=150):
image = Image.open(infile)
image = image.resize((resize, resize))
result = image.convert('P', palette=Image.ADAPTIVE, colors=numcolors)
result.putalpha(0)
colors = result.getcolors(resize*resize)