Skip to content

Instantly share code, notes, and snippets.

@FLamparski
Created January 1, 2015 14:42
Show Gist options
  • Save FLamparski/a57f6d5f1e9953236f77 to your computer and use it in GitHub Desktop.
Save FLamparski/a57f6d5f1e9953236f77 to your computer and use it in GitHub Desktop.
Get swatches from Adobe Color CC
from urllib.parse import parse_qs
from itertools import islice
def get_colors_from_kuler(kuler_url, count=5):
"""Get colors from a Adobe Kuler/Color CC URL.
You can't easily export these colour schemes, since the only
save feature Adobe implemented uses the Adobe account. However,
raw color values are stored in the URL in a somewhat unwieldy
but still straightforward format. Basically,
it uses a `rgbvalues=r0,g0,b0...rN,gN,bN` list, which this
function will decode. The output format is a list of 3-tuples:
[ (r, g, b), (r, g, b), ... ]
"""
qs = kuler_url.split('?')[1]
qv = parse_qs(qs)
values = [float(x) for x in qv['rgbvalues'][0].split(',')]
indices = [(pos * 3, (pos * 3) + 3) for pos in range(count)]
swatches = [tuple(islice(values, *slc)) for slc in indices]
return swatches
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment