@@ -14,12 +14,27 @@ import (
1414var (
1515 colorB string
1616 BorderThickness int
17+
18+ gridSize int
19+ gridColor string
20+ gridThickness int
21+ gridMask bool
1722)
1823
1924var drawCmd = & cobra.Command {
20- Use : "draw [PATH] [OPTIONAL OUTPUT]" ,
21- Short : "draw a border with a color and thickness (currently)" ,
22- Long : `The draw command allows you to draw a plethora of effects. Currently only drawing a border is supported with more to come` ,
25+ Use : "draw [DRAW-COMMAND] [INPUT] [OPTIONAL OUTPUT]" ,
26+ Short : "Draw on images" ,
27+ Long : `Draw a [border,grid] in your images` ,
28+ Run : func (cmd * cobra.Command , args []string ) {
29+ logger .Print ("Please specify an draw command to apply" )
30+ err := cmd .Usage ()
31+ utils .HandleError (err )
32+ },
33+ }
34+
35+ var GridCmd = & cobra.Command {
36+ Use : "grid [PATH] [OPTIONAL OUTPUT]" ,
37+ Short : "draw a grid with a specific size,color and thickness on the image" ,
2338 PreRunE : func (cmd * cobra.Command , args []string ) error {
2439 err := validateInput (shared , args )
2540 if err != nil {
@@ -28,19 +43,45 @@ var drawCmd = &cobra.Command{
2843 return nil
2944 },
3045 Run : func (cmd * cobra.Command , args []string ) {
31- if len (args ) > 0 {
32- logger .Print ("Processing single image..." )
46+ imageOps , err := imageio .DetermineImageOperations (shared , args )
47+ utils .HandleError (err )
48+ logger .Print ("Processing images..." )
49+
50+ processor := & image.GridProcessor {}
51+ processor .SetGridOptions (
52+ image .WithGridSize (gridSize ),
53+ image .WithGridColor (gridColor ),
54+ image .WithGridThickness (gridThickness ),
55+ image .WithMaskonly (gridMask ),
56+ )
57+ processedImages , err := image .ProcessImgs (processor , imageOps , theme )
58+ utils .HandleError (err , "Error" )
59+
60+ if err != nil {
61+ logger .Error (err , "The following images had errors while processing" )
3362 }
34- if isInputBatch (shared ) {
35- logger .Print ("Processing batch of images..." )
63+ openImageInViewer (shared , args , processedImages [0 ])
64+ },
65+ }
66+
67+ var BorderCmd = & cobra.Command {
68+ Use : "border [PATH] [OPTIONAL OUTPUT]" ,
69+ Short : "draw a border with a specified color and thickness on the image" ,
70+ PreRunE : func (cmd * cobra.Command , args []string ) error {
71+ err := validateInput (shared , args )
72+ if err != nil {
73+ return err
3674 }
75+ return nil
76+ },
77+ Run : func (cmd * cobra.Command , args []string ) {
3778 hex , err := cmd .Flags ().GetString ("color" )
3879 utils .HandleError (err , "Error" )
3980
4081 clr , err := image .HexToRGBA (hex )
4182 utils .HandleError (err , "Error" )
4283
43- processor := & image.DrawProcessor {
84+ processor := & image.BorderProcessor {
4485 Color : clr ,
4586 BorderThickness : BorderThickness ,
4687 }
@@ -53,10 +94,6 @@ var drawCmd = &cobra.Command{
5394 processedImages , err := image .ProcessImgs (processor , imageOps , theme )
5495 utils .HandleError (err , "Error" )
5596
56- // if len(processedImages) == 0 {
57- // utils.HandleError(err, "No images were processed")
58- // }
59-
6097 if err != nil {
6198 logger .Error (err , "The following images had errors while processing" )
6299 }
@@ -67,7 +104,16 @@ var drawCmd = &cobra.Command{
67104
68105func init () {
69106 rootCmd .AddCommand (drawCmd )
70- drawCmd .Flags ().StringVarP (& colorB , "color" , "c" , "#5D3FD3" , "--color #5D3FD3" )
71- drawCmd .Flags ().IntVarP (& BorderThickness , "borderThickness" , "b" , 5 , "-b 5" )
107+
108+ drawCmd .AddCommand (BorderCmd )
109+ drawCmd .AddCommand (GridCmd )
110+
111+ BorderCmd .Flags ().StringVarP (& colorB , "color" , "c" , "#5D3FD3" , "--color #5D3FD3" )
112+ BorderCmd .Flags ().IntVarP (& BorderThickness , "borderThickness" , "b" , 5 , "-b 5" )
113+ GridCmd .Flags ().IntVarP (& gridSize , "size" , "s" , 80 , "--size 80" )
114+ GridCmd .Flags ().IntVarP (& gridThickness , "thickness" , "t" , 1 , "--thickness 1" )
115+ GridCmd .Flags ().StringVarP (& gridColor , "color" , "c" , "#5D3FD3" , "--color #5D3FD3" )
116+ GridCmd .Flags ().BoolVarP (& gridMask , "mask" , "m" , false , "--mask true to use apply the grid only to transparent pixels (background)" )
117+
72118 addGlobalFlags (drawCmd )
73119}
0 commit comments