colorgram python

Solutions on MaxInterview for colorgram python by the best coders in the world

showing results for - "colorgram python"
Adrián
24 Jan 2018
1import colorgram
2
3# Extract 6 colors from an image.
4colors = colorgram.extract('sweet_pic.jpg', 6)
5
6# colorgram.extract returns Color objects, which let you access
7# RGB, HSL, and what proportion of the image was that color.
8first_color = colors[0]
9rgb = first_color.rgb # e.g. (255, 151, 210)
10hsl = first_color.hsl # e.g. (230, 255, 203)
11proportion  = first_color.proportion # e.g. 0.34
12
13# RGB and HSL are named tuples, so values can be accessed as properties.
14# These all work just as well:
15red = rgb[0]
16red = rgb.r
17saturation = hsl[1]
18saturation = hsl.s
19