palitra

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 11, 2018 License: MIT Imports: 7 Imported by: 1

README

palitra

Build Status GoDoc Go Report Card

Example image

Description

Utility that finds the N most frequent colors in a picture, approximated to CSS3 color names. Palitra is available both as a plain library, and as a CLI tool (which also supports input from stdin, via pipe). It requires Go 1.8.

Install

You can download the library with go get:

$ go get github.com/jkomyno/palitra

If you want to use the CLI tool, then you can type the following to install it in your environment.

$ go install github.com/jkomyno/palitra/cmd/palitra

Usage

CLI

This guide assumes that palitra is installed globally.

Here's how palitra --help looks like:

Usage of C:\Work\GoWorkspace\bin\palitra.exe:
  -img string
        the name of the image file to get colors from
  -n int
        the number of the most dominant CSS3 colors to extract (default 3)
  -r uint
        the resized width to process the image quicker (default 75)

If you're ok with the default values, then you can simply pipe an image to palitra. Example:

$ cat ./test_images/venice.jpg | palitra

The result should look like the following:

1) lightpink: 10.48%
2) lightslategrey: 9.97%
3) dimgrey: 9.61%

Completed in 679.7955ms ✨

If not, you can manually specify the parameters as you like:

$ palitra -img ./test_images/venice.jpg -n 5 -r 50

The result should look like the following:

1) lightpink: 10.34%
2) dimgrey: 10.04%
3) lightslategrey: 9.93%
4) silver: 9.15%
5) darkslategrey: 8.81%

Completed in 290.7805ms ✨
Library

For the library usage, please refer to godoc. You can import the library in the following way:

import "github.com/jkomyno/palitra"

Testing

$ go test -v -bench=.

License

The MIT License (MIT). Please see License File for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColorPercentageT

type ColorPercentageT struct {
	Color      string `json:"color"`
	Percentage string `json:"percentage"`
}

ColorPercentageT is a struct which contains the approximated CSS3 color `Color` and its spread in the image, expressed as `Percentage`%

func GetPalette

func GetPalette(img image.Image, paletteLimit int, resizeWidth uint) []ColorPercentageT

GetPalette returns an array of `paletteLen` colors, given an image `img`. To enhance performance, a `resizeWidth` param is required.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL