forked from anthonynsimon/bild
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnoise.go
48 lines (37 loc) · 1.04 KB
/
noise.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
package cmd
import (
"github.com/anthonynsimon/bild/imgio"
"github.com/anthonynsimon/bild/noise"
"github.com/spf13/cobra"
)
func generateNoise() *cobra.Command {
size := ""
mono := false
var cmd = &cobra.Command{
Use: "new",
Short: "generates an image filled with noise",
Args: cobra.ExactArgs(1),
Example: "new -s 100x100 output.png",
Run: func(cmd *cobra.Command, args []string) {
fout := args[0]
size, err := parseSizeStr(size)
exitIfNotNil(err)
result := noise.Generate(size.Width, size.Height, &noise.Options{
Monochrome: mono,
})
encoder := resolveEncoder(fout, imgio.PNGEncoder())
err = imgio.Save(fout, result, encoder)
exitIfNotNil(err)
}}
cmd.Flags().StringVarP(&size, "size", "s", "512x512", "the width and height of the output image")
cmd.Flags().BoolVarP(&mono, "monochrome", "m", false, "output monochrome noise")
return cmd
}
func createNoise() *cobra.Command {
var cmd = &cobra.Command{
Use: "noise",
Short: "noise generators",
}
cmd.AddCommand(generateNoise())
return cmd
}