-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
60 lines (49 loc) · 1.07 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"flag"
"fmt"
"github.com/xyproto/palgen"
"image/color/palette"
"image/png"
"os"
)
func main() {
var (
outputFilename string
version bool
err error
notsorted bool
)
flag.StringVar(&outputFilename, "o", "websafe.png", "output PNG filename")
flag.BoolVar(&version, "v", false, "version")
flag.BoolVar(¬sorted, "u", true, "unsorted")
flag.Parse()
if version {
fmt.Println("websafe 1.0.1")
os.Exit(0)
}
// Prepare to output the new PNG data to either stdout or to file
f := os.Stdout
if outputFilename != "-" {
f, err = os.Create(outputFilename)
if err != nil {
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
defer f.Close()
}
// Get the WebSafe palette
pal := palette.WebSafe
// Sort the palette by hue, luminance and chroma
if !notsorted {
palgen.Sort(pal)
}
// Render the palette as an image
palImage := palgen.Render(pal)
// Output the rendered image
if err := png.Encode(f, palImage); err != nil {
f.Close()
fmt.Fprintf(os.Stderr, "error: %s\n", err)
os.Exit(1)
}
}