Documentation ¶
Overview ¶
Extract prominent colors from images. Go port of the Android Palette class aka Vibrant.js
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;}
Index ¶
Constants ¶
View Source
const ( DEFAULT_CALCULATE_NUMBER_COLORS = 256 TARGET_DARK_LUMA = 0.26 MAX_DARK_LUMA = 0.45 MIN_LIGHT_LUMA = 0.55 TARGET_LIGHT_LUMA = 0.74 MIN_NORMAL_LUMA = 0.3 TARGET_NORMAL_LUMA = 0.5 MAX_NORMAL_LUMA = 0.7 TARGET_MUTED_SATURATION = 0.3 MAX_MUTED_SATURATION = 0.4 TARGET_VIBRANT_SATURATION = 1 MIN_VIBRANT_SATURATION = 0.35 WEIGHT_SATURATION = 3 WEIGHT_LUMA = 6 WEIGHT_POPULATION = 1 MIN_CONTRAST_TITLE_TEXT = 3.0 MIN_CONTRAST_BODY_TEXT = 4.5 )
These constants are taken directly from the Android Palette source code, with the exception of DEFAULT_CALCULATE_NUMBER_COLORS which was 16.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Color ¶
type Color int
func (Color) BodyTextColor ¶
Returns either black or white based on MIN_CONTRAST_BODY_TEXT
func (Color) TitleTextColor ¶
Returns either black or white based on MIN_CONTRAST_TITLE_TEXT
type Palette ¶
type Palette struct {
// contains filtered or unexported fields
}
func NewPaletteFromImage ¶
Calls NewPalette with DEFAULT_CALCULATE_NUMBER_COLORS as a default value for numColors.
func (*Palette) ExtractAwesome ¶
Possible map keys are:
Vibrant LightVibrant DarkVibrant Muted LightMuted DarkMuted
Some or all of these keys might not be set depending on the source image and numColors parameters used when creating the Palette. YMMV
Source Files ¶
Click to show internal directories.
Click to hide internal directories.