-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
178 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"sync" | ||
|
||
"github.com/mass8326/imgchop/lib/imgchop" | ||
"github.com/mass8326/imgchop/lib/logger" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var version = "[N/A]" | ||
|
||
func Execute() { | ||
var flags RootFlags | ||
|
||
cmd := &cobra.Command{ | ||
Use: filepath.Base(os.Args[0]) + " [flags] [paths...]", | ||
Short: "Chop your images into squares", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) == 0 { | ||
cmd.Help() | ||
logger.Exit(1) | ||
} | ||
|
||
warning := false | ||
var wg sync.WaitGroup | ||
for _, file := range args { | ||
wg.Add(1) | ||
go imgchop.Process(&wg, &warning, file, *flags.intelligent) | ||
} | ||
wg.Wait() | ||
|
||
if warning { | ||
logger.Exit(0) | ||
} | ||
}, | ||
Version: version, | ||
} | ||
|
||
flags = initFlags(cmd) | ||
|
||
err := cmd.Execute() | ||
if err != nil { | ||
logger.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cmd | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
type RootFlags struct { | ||
intelligent *bool | ||
} | ||
|
||
func initFlags(cmd *cobra.Command) RootFlags { | ||
cmd.PersistentFlags().Bool("help", false, "print help message") | ||
cmd.PersistentFlags().Bool("version", false, "print version") | ||
cmd.SetVersionTemplate("{{.Version}}\n") | ||
|
||
return RootFlags{ | ||
intelligent: cmd.PersistentFlags().BoolP("intelligent", "i", false, "enable intelligent filter"), | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package util | ||
|
||
import "image/color" | ||
|
||
func ColorToNRGB(clr color.Color) (r uint8, g uint8, b uint8) { | ||
r16, g16, b16, a16 := clr.RGBA() | ||
factor := float32(a16) / float32(65535) | ||
nr8 := uint32(float32(r16)/factor) >> 8 | ||
ng8 := uint32(float32(g16)/factor) >> 8 | ||
nb8 := uint32(float32(b16)/factor) >> 8 | ||
return uint8(nr8), uint8(ng8), uint8(nb8) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package util | ||
|
||
import "github.com/inconshreveable/mousetrap" | ||
|
||
var StartedByExplorer = mousetrap.StartedByExplorer() |