@@ -28,7 +28,7 @@ import (
2828
2929func Local (a []string ) {
3030 // Validate arguments and get parameters
31- if len (a ) != 2 {
31+ if len (a ) != 3 {
3232 Help (nil )
3333 return
3434 }
@@ -55,45 +55,59 @@ func Local(a []string) {
5555 return
5656 }
5757
58- // Create graphic
59- rectangle := image .Rect (0 , 0 , width , height )
60- graphic := image .NewRGBA (rectangle )
61-
62- fill := color.RGBA {
63- R : uint8 (rand .Int ()),
64- G : uint8 (rand .Int ()),
65- B : uint8 (rand .Int ()),
66- A : uint8 (rand .Int ()),
67- }
68-
69- for x := range width {
70- for y := range height {
71- graphic .SetRGBA (x , y , fill )
72- }
73- }
74-
75- // Create file
76- directory , err := os .UserHomeDir ()
58+ count , err := strconv .Atoi (a [2 ])
7759 if err != nil {
7860 fmt .Fprintf (os .Stderr , "%s\n " , strings .ToLower (err .Error ()))
7961 return
8062 }
8163
82- path := filepath .Join (directory , "local.jpg" )
83-
84- file , err := os .Create (path )
85- if err != nil {
86- fmt .Fprintf (os .Stderr , "%s\n " , strings .ToLower (err .Error ()))
64+ if count < 1 {
65+ fmt .Fprintf (os .Stderr , "%s\n " , strings .ToLower (errInvalidCount .Error ()))
8766 return
8867 }
8968
90- // Encode graphic into the file
91- err = jpeg .Encode (file , graphic , nil )
92- if err != nil {
93- fmt .Fprintf (os .Stderr , "%s\n " , strings .ToLower (err .Error ()))
94- return
95- }
69+ for i := range count {
70+ // Create graphic
71+ rectangle := image .Rect (0 , 0 , width , height )
72+ graphic := image .NewRGBA (rectangle )
9673
97- // Print message
98- fmt .Fprintf (os .Stdout , "Image saved in \" %s\" \n " , path )
74+ fill := color.RGBA {
75+ R : uint8 (rand .Intn (256 )),
76+ G : uint8 (rand .Intn (256 )),
77+ B : uint8 (rand .Intn (256 )),
78+ A : uint8 (rand .Intn (256 )),
79+ }
80+
81+ for x := range width {
82+ for y := range height {
83+ graphic .SetRGBA (x , y , fill )
84+ }
85+ }
86+
87+ // Create file
88+ directory , err := os .UserHomeDir ()
89+ if err != nil {
90+ fmt .Fprintf (os .Stderr , "%s\n " , strings .ToLower (err .Error ()))
91+ return
92+ }
93+
94+ name := fmt .Sprintf ("local-%d.jpg" , i + 1 )
95+ path := filepath .Join (directory , name )
96+
97+ file , err := os .Create (path )
98+ if err != nil {
99+ fmt .Fprintf (os .Stderr , "%s\n " , strings .ToLower (err .Error ()))
100+ return
101+ }
102+
103+ // Encode graphic into the file
104+ err = jpeg .Encode (file , graphic , nil )
105+ if err != nil {
106+ fmt .Fprintf (os .Stderr , "%s\n " , strings .ToLower (err .Error ()))
107+ return
108+ }
109+
110+ // Print message
111+ fmt .Fprintf (os .Stdout , "Image saved in \" %s\" \n " , path )
112+ }
99113}
0 commit comments