Last active
July 17, 2018 03:05
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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