🎨 Simple color palette quantization using MMCQ
You can fetch this library by running the following
go get -u github.com/joshdk/quantize
import (
"image/color""image/jpeg""net/http""github.com/joshdk/preview""github.com/joshdk/quantize"
)
// Fetch the source imageresp, err:=http.Get("https://blog.golang.org/gopher/plush.jpg")
iferr!=nil {
panic(err.Error())
}
// Decode jpeg contentsimg, err:=jpeg.Decode(resp.Body)
iferr!=nil {
panic(err.Error())
}
// Reduce image into a palette of 8 colorscolors:=quantize.Image(img, 3)
palette:=make([]color.Color, len(colors))
forindex, clr:=rangecolors {
palette[index] =clr
}
// Display our new palettepreview.Show(palette)As an example, we can reduce a photo of the Go Gopher (source) into a color palette.
This library is distributed under the MIT License, see LICENSE.txt for more information.
