Skip to content

Instantly share code, notes, and snippets.

@zaiste
Created January 18, 2018 17:57
Show Gist options
  • Save zaiste/3208d9729d49f07a38ff050cdbdec5fe to your computer and use it in GitHub Desktop.
Save zaiste/3208d9729d49f07a38ff050cdbdec5fe to your computer and use it in GitHub Desktop.
Extract colors in Python
import sys
import json
from haishoku.haishoku import Haishoku
colors = []
if len(sys.argv) > 1:
url = sys.argv[1]
try:
palette = Haishoku.getPalette(url)
colors = [{'hex': '#%02x%02x%02x' % color[1], 'ratio': color[0]} for color in palette]
except:
pass
print(json.dumps(colors))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment