Skip to content

Instantly share code, notes, and snippets.

@svschannak
Last active January 3, 2016 19:39
Show Gist options
  • Save svschannak/8509908 to your computer and use it in GitHub Desktop.
Save svschannak/8509908 to your computer and use it in GitHub Desktop.
Get most used color from an image and its complementary color with python and PIL.
pic = Image.open('/path/to/image.jpg')
sorted_list = sorted(pic.getcolors(pic.size[0]*pic.size[1]))
#get complementary color of picture
comp = ['%s' % (255 - int(a)) for a in sorted_list[-1][1]]
color1 = '#%02x%02x%02x' % (sorted_list[-1][1])
color2 = '#%02x%02x%02x' % (int(comp[0]), int(comp[1]), int(comp[2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment