Skip to content

Instantly share code, notes, and snippets.

@robot-o
Last active July 17, 2018 03:05
Show Gist options
  • Save robot-o/d3176afd42837f04b62c3923dd4ab85e to your computer and use it in GitHub Desktop.
Save robot-o/d3176afd42837f04b62c3923dd4ab85e to your computer and use it in GitHub Desktop.
lists all colors in image provided as first argument in hex and rgb
#!/usr/bin/env python2.7
import sys
from PIL import Image
im = Image.open(sys.argv[1])
w, h = im.size
colors = []
for x in range (w):
for y in range(h):
rgb = im.getpixel((x,y))
if rgb not in colors:
colors.append(rgb)
print "unique colors (rgb):"
print colors
print "unique colors (hex):"
hexcolors = []
for x in colors:
hexcolors.append('#%02x%02x%02x' % x)
print hexcolors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment