-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgodoc.go
46 lines (31 loc) · 1.23 KB
/
godoc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
Extract prominent colors from images. Go port of the Android Palette class aka Vibrant.js
https://android.googlesource.com/platform/frameworks/support/+/b14fc7c/v7/palette/src/android/support/v7/graphics/
https://github.com/jariz/vibrant.js
// example: create css stylesheet from image file
checkErr := func(err error) { if err != nil { panic(err) } }
f, err := os.Open("some_image.jpg")
checkErr(err)
defer f.Close()
img, _, err := image.Decode(f)
checkErr(err)
palette, err := vibrant.NewPaletteFromImage(img)
checkErr(err)
for name, swatch := range palette.ExtractAwesome() {
fmt.Printf("/* %s (population: %d) *\/\n%s\n\n", name, swatch.Population, swatch)
}
output:
/* LightMuted (population: 253) *\/
.lightmuted{background-color:#cbc0a2;color:#000000;}
/* DarkMuted (population: 11069) *\/
.darkmuted{background-color:#5b553f;color:#ffffff;}
/* Vibrant (population: 108) *\/
.vibrant{background-color:#dfd013;color:#000000;}
/* LightVibrant (population: 87) *\/
.lightvibrant{background-color:#f4ed7d;color:#000000;}
/* DarkVibrant (population: 2932) *\/
.darkvibrant{background-color:#917606;color:#ffffff;}
/* Muted (population: 4098) *\/
.muted{background-color:#a58850;color:#000000;}
*/
package vibrant