Skip to content

Instantly share code, notes, and snippets.

@hawx
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hawx/11262427 to your computer and use it in GitHub Desktop.
Save hawx/11262427 to your computer and use it in GitHub Desktop.
Dominant Palette Drawer
// Usage: dominant < in > out
package main
import (
"github.com/hawx/img/utils"
"github.com/hawx/rgoybiv"
"image"
"image/draw"
)
func main() {
img, exif := utils.ReadStdin()
palette := rgoybiv.GetPalette(img, nil)
const (
rowWidth = 500
rowHeight = 75
rowMargin = 25
rowCount = 5
)
bounds := image.Rect(0, 0, rowWidth + 2 * rowMargin, rowHeight * rowCount + rowMargin * (rowCount + 1))
row := image.Rect(rowMargin, rowMargin, rowMargin + rowWidth, rowMargin + rowHeight)
diff := image.Pt(0, rowMargin + rowHeight)
out := image.NewRGBA(bounds)
draw.Draw(out, bounds, image.White, image.ZP, draw.Src)
for i := 0; i < rowCount; i++ {
draw.Draw(out, row, &image.Uniform{palette.Colors[i].Value}, image.ZP, draw.Src)
row = row.Add(diff)
}
utils.WriteStdout(out, exif)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment