Go package for working with colours, principally colour extraction and "snap to grid"
You will need to have both Go
(specifically version 1.12 or higher because we're using Go modules) and the make
programs installed on your computer. Assuming you do just type:
make tools
All of this package's dependencies are bundled with the code in the vendor
directory.
This is work in progress. Eventually it will be a complete port of the py-cooperhewitt-swatchbook and py-cooperhewitt-roboteyes-colors (and by extension RoyGBiv) packages, but today it is only a partial implementation.
Also, this documentation is incomplete.
package main
import (
"flag"
"github.com/aaronland/go-colours/extruder"
"github.com/aaronland/go-colours/grid"
"github.com/aaronland/go-colours/palette"
"image"
_ "image/jpeg"
"log"
"os"
)
func main() {
flag.Parse()
ex, _ := extruder.NewNamedExtruder("vibrant")
gr, _ := grid.NewNamedGrid("euclidian")
p, _ := palette.NewNamedPalette("css4")
for _, path := range flag.Args() {
fh, _ := os.Open(path)
im, _, _ := image.Decode(fh)
colours, _ := ex.Colours(im, 5)
for _, c := range colours {
closest, _ := gr.Closest(c, p)
for _, cl := range closest {
log.Println(c, cl)
}
}
}
}
Note that error handling has been removed for the sake of brevity.
type Colour interface {
Name() string
Hex() string
Reference() string
Closest() []Colour
AppendClosest(Colour) error // I don't love this... (20180605/thisisaaronland)
String() string
}
type Extruder interface {
Colours(image.Image, int) ([]Colour, error)
}
type Grid interface {
Closest(Colour, Palette) (Colour, error)
}
type Palette interface {
Reference() string
Colours() []Colour
}
Extruders are the things that generate a palette of colours for an image.Image
.
This returns colours using the vibrant package but rather than ranking colours using a particular metric it returns specific named "swatches" that are recast as colours.Colour
interfaces. They are: VibrantSwatch, LightVibrantSwatch, DarkVibrantSwatch, MutedSwatch, LightMutedSwatch, DarkMutedSwatch
.
Grids are the things that perform operations or compare colours.
Palettes are a fixed set of colours.