...

Package quantize

import "github.com/ericpauley/go-quantize/quantize"
Overview
Index
Examples

Overview ▾

Package quantize offers an implementation of the draw.Quantize interface using an optimized Median Cut method, including advanced functionality for fine-grained control of color priority

type AggregationType

AggregationType specifies the type of aggregation to be done

type AggregationType uint8
const (
    // Mode - pick the highest priority value
    Mode AggregationType = iota
    // Mean - weighted average all values
    Mean
)

type MedianCutQuantizer

MedianCutQuantizer implements the go draw.Quantizer interface using the Median Cut method

type MedianCutQuantizer struct {
    // The type of aggregation to be used to find final colors
    Aggregation AggregationType
    // The weighting function to use on each pixel
    Weighting func(image.Image, int, int) uint32
    // Whether to create a transparent entry
    AddTransparent bool
}

Example

Code:

file, err := os.Open("test_image.jpg")
if err != nil {
    fmt.Println("Couldn't open test file")
    return
}
i, _, err := image.Decode(file)
if err != nil {
    fmt.Println("Couldn't decode test file")
    return
}
q := MedianCutQuantizer{}
p := q.Quantize(make([]color.Color, 0, 256), i)
fmt.Println(p)

func (MedianCutQuantizer) Quantize

func (q MedianCutQuantizer) Quantize(p color.Palette, m image.Image) color.Palette

Quantize quantizes an image to a palette and returns the palette