The Wayback Machine - https://web.archive.org/web/20201027173114/https://github.com/joshdk/quantize
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
cmd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

License GoDoc Go Report Card CircleCI CodeCov

Quantize

🎨 Simple color palette quantization using MMCQ

Installing

You can fetch this library by running the following

go get -u github.com/joshdk/quantize

Usage

import (
	"image/color"
	"image/jpeg"
	"net/http"
	"github.com/joshdk/preview"
	"github.com/joshdk/quantize"
)

// Fetch the source image
resp, err := http.Get("https://blog.golang.org/gopher/plush.jpg")
if err != nil {
	panic(err.Error())
}

// Decode jpeg contents
img, err := jpeg.Decode(resp.Body)
if err != nil {
	panic(err.Error())
}

// Reduce image into a palette of 8 colors
colors := quantize.Image(img, 3)

palette := make([]color.Color, len(colors))
for index, clr := range colors {
	palette[index] = clr
}

// Display our new palette
preview.Show(palette)

As an example, we can reduce a photo of the Go Gopher (source) into a color palette.

gopher

License

This library is distributed under the MIT License, see LICENSE.txt for more information.

About

🎨 Simple color palette quantization using MMCQ

Topics

Resources

License

Packages

No packages published
You can’t perform that action at this time.