package module
v0.0.0-...-b990f14 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2016 License: MIT Imports: 11 Imported by: 0


Coloris (beta) Go Report Card Docs License

go get

Process image to get most used colors.
And return color names that are closest to original colors.
By default skips Black, White and true Gray (#808080) color.

Can be used different color palettes for final color list:

  • Palette_ColorNames3
  • Palette_ColorNames12 -- default
  • Palette_ColorNames26
  • Palette_ColorNamesMAX -- very slow for now



    // Collect colors
    clist := coloris.AllColors("path/to/image.jpg", nil)

    // Print color info
    for _, c := range clist {
        // c.Name       - closest color name
        // c.NameHex    - closest color hex code
        // c.Count      - color pixel count
        // c.Percents   - color usage in image

        fmt.Println(c.Name, c.Percents) // Blue 20%


Also can use these functions


    // Get only top 3 colors
    clist := coloris.TopColors("path/to/image.jpg", 3, nil)

    // Get 3 least used colors
    clist := coloris.TopColors("path/to/image.jpg", -3, nil)

    // ONE most used color
    clr := coloris.DominantColor("path/to/image.jpg", nil)



(c) Photo by refreshment_66 --
(c) Photo by Sarah J --
(c) Photo by GLOBAL 2000 --

Dependency and Thanks

**Color names ** for Palette_ColorNamesMAX palette --
Color functions --

Bugs & TODO's

  • Using Palette_ColorNamesMAX is too slow
  • Need more tests for code coverage 100%




This section is empty.


View Source
var Palette_ColorNames12 = map[string]string{
	"#000000": "Black",
	"#ffffff": "White",
	"#808080": "Gray",
	"#c41414": "Red",
	"#00ff00": "Green Lime",
	"#2874E6": "Blue",
	"#FFFF00": "Yellow",
	"#FF681F": "Orange",
	"#9d3909": "Brown",
	"#BAE9F3": "Light Blue",
	"#FF00FF": "Pink",
	"#DAFC4F": "Canary",
	"#228B22": "Green",
	"#881e88": "Purple",

Palette_ColorNames12 - Main 12 colors

View Source
var Palette_ColorNames26 = map[string]string{
	"#000000": "Black",
	"#FFFFFF": "White",
	"#808080": "Gray",
	"#0000FF": "Blue",
	"#2874E6": "Royal Blue",
	"#BAE9F3": "Light Blue",
	"#808000": "Olive",
	"#A7C261": "Celery",
	"#008000": "Green",
	"#00FF00": "Lime Green",
	"#DAFC4F": "Canary",
	"#F0E891": "Khaki",
	"#8e1c1c": "Maroon",
	"#B44848": "Chestnut",
	"#B5651D": "Brown",
	"#CC8454": "Raw Sienna",
	"#FDD9B5": "Apricot",
	"#800080": "Purple",
	"#6658B6": "Blue Violet",
	"#C285DB": "Lavender",
	"#FF00FF": "Pink",
	"#FFAACC": "Carnation Pink",
	"#DA3163": "Cerise Red",
	"#FF0000": "Red",
	"#FF4800": "Red Orange",
	"#FF681F": "Orange",
	"#FF9900": "Yellow Orange",
	"#FFCC00": "Golden Yellow",
	"#FFFF00": "Yellow",

Palette_ColorNames26 - Main 26 colors

View Source
var Palette_ColorNames3 = map[string]string{
	"#000000": "Black",
	"#ffffff": "White",
	"#c41414": "Red",
	"#228B22": "Green",
	"#2874E6": "Blue",

Palette_ColorNames3 - Main 3 colors

View Source
var Palette_ColorNamesMAX = map[string]string{}/* 1566 elements not displayed */

Palette_ColorNamesMAX - Colors with all names

View Source
var Palette_Default = Palette_ColorNames12

Palette_Default - default color map


This section is empty.


type Collection

type Collection struct {
	// contains filtered or unexported fields

Collection of color lists

func NewCollection

func NewCollection(im *Image) *Collection

NewCollection - Collection and initialize lists

func (*Collection) Add

func (col *Collection) Add(_c color.Color)

Add - add color

func (*Collection) CollectStats

func (col *Collection) CollectStats()

CollectStats - trigger stats gathering from lists

func (*Collection) Find

func (col *Collection) Find(c *Color) *Color

Find - find color by given color can be used to chekc if color already exists

type Color

type Color struct {
	Count         int // color px count on image
	Percents      float64
	ColorfulColor colorful.Color
	Name          string // color name
	NameHex       string // exact color hex
	// contains filtered or unexported fields

Color - coloris color type

func DominantColor

func DominantColor(fpath string, palette map[string]string) *Color

DominantColor - get one color that are mostly used If two color on same count use first as comes

func NewColor

func NewColor(_c color.Color) *Color

NewColor - get package color struct

func (*Color) Print

func (c *Color) Print()

Print color fields

func (*Color) SetName

func (c *Color) SetName() string

SetName - find name for given color

type ColorList

type ColorList []*Color

ColorList - color list of colors

func AllColors

func AllColors(fpath string, palette map[string]string) ColorList

AllColors - Return all collected colors from image

func BytesToAllColors

func BytesToAllColors(buf []byte, palette map[string]string) ColorList

BytesToAllColors - Return all collected colors from bytes

func TopColors

func TopColors(fpath string, limit int, palette map[string]string) ColorList

TopColors - Return top n colors from image

func (*ColorList) FindByName

func (clist *ColorList) FindByName(name string) *Color

FindByName - is already exists in list

func (ColorList) Len

func (clist ColorList) Len() int

Len is part of sort.Interface.

func (ColorList) Less

func (clist ColorList) Less(i, j int) bool

Less is part of sort.Interface. We use count as the value to sort by

func (ColorList) Print

func (clist ColorList) Print()

Print colors

func (ColorList) Swap

func (clist ColorList) Swap(i, j int)

Swap is part of sort.Interface.

type Image

type Image struct {
	Palette    map[string]string // use these colors to detect color names
	SkipColors []string
	Collection *Collection
	// contains filtered or unexported fields

Image data

func NewImage

func NewImage(fpath string, palette map[string]string) *Image

NewImage - load and process image

func NewImageFromBytes

func NewImageFromBytes(buf []byte, palette map[string]string) *Image

NewImageFromBytes - load and process image

func (*Image) AllColors

func (im *Image) AllColors() ColorList

AllColors - Return all collected colors from image

func (*Image) DominantColor

func (im *Image) DominantColor() *Color

DominantColor - get one color that are mostly used If two color on same count use first as comes

func (*Image) Process

func (im *Image) Process(fpath string) error

Process - from image path

func (*Image) ProcessBytes

func (im *Image) ProcessBytes(freader io.Reader) error

ProcessBytes - from bytes

func (*Image) TopColors

func (im *Image) TopColors(limit int) ColorList

TopColors - Return top n colors from image


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL