diff --git a/cmd/manga-translator/main.go b/cmd/manga-translator/main.go index 091b6af..47e389c 100644 --- a/cmd/manga-translator/main.go +++ b/cmd/manga-translator/main.go @@ -48,13 +48,20 @@ func main() { if !*clipImagePtr { imgPath = flag.Args() log.Infof("All Selected Image(s): %v", imgPath) + } else { + // Need a single element in the array so that it will try to open 1 image. The path itself is not used. + imgPath = append(imgPath, "clipboard") + } + + if len(imgPath) == 0 { + log.Fatal("No images provided.") } var img []imageW.TranslatorImage - for _, imgPath := range imgPath { + for _, paths := range imgPath { log.Debugf("Getting image info for: %v", imgPath) - newImage := imageW.Open(imgPath, *urlImagePtr, *clipImagePtr) + newImage := imageW.Open(paths, *urlImagePtr, *clipImagePtr) img = append(img, newImage) } diff --git a/go.mod b/go.mod index dd66d31..2485013 100644 --- a/go.mod +++ b/go.mod @@ -10,8 +10,8 @@ require ( github.com/inancgumus/screen v0.0.0-20190314163918-06e984b86ed3 github.com/sirupsen/logrus v1.8.1 github.com/spf13/viper v1.11.0 - golang.design/x/clipboard v0.5.3 - golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d + golang.design/x/clipboard v0.6.2 + golang.org/x/image v0.0.0-20211028202545-6944b10bf410 golang.org/x/text v0.3.7 google.golang.org/api v0.74.0 google.golang.org/genproto v0.0.0-20220414192740-2d67ff6cf2b4 diff --git a/go.sum b/go.sum index 941965b..f622dd2 100644 --- a/go.sum +++ b/go.sum @@ -256,6 +256,8 @@ go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= golang.design/x/clipboard v0.5.3 h1:JUxlkxohMUtpFcwPu1JjsAlkndNq8UVVeOBDAGE/il8= golang.design/x/clipboard v0.5.3/go.mod h1:ep0pB+/4DGJK3ayLxweWJFHhHGGv3npJJHMXAjtLTUM= +golang.design/x/clipboard v0.6.2 h1:a3Np4qfKnLWwfFJQhUWU3IDeRfmVuqWl+QPtP4CSYGw= +golang.design/x/clipboard v0.6.2/go.mod h1:kqBSweBP0/im4SZGGjLrppH0D400Hnfo5WbFKSNK8N4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -282,6 +284,8 @@ golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMx golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs= golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= +golang.org/x/image v0.0.0-20211028202545-6944b10bf410 h1:hTftEOvwiOq2+O8k2D5/Q7COC7k5Qcrgc2TFURJYnvQ= +golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/pkg/image/image.go b/pkg/image/image.go index 395290a..1cc0fcd 100644 --- a/pkg/image/image.go +++ b/pkg/image/image.go @@ -38,6 +38,14 @@ func Open(file string, url, clip bool) TranslatorImage { var size int if clip { + var err error + + // Init returns an error if the package is not ready for use. + err = clipboard.Init() + if err != nil { + log.Fatal(err) + } + imgByte := clipboard.Read(clipboard.FmtImage) if imgByte == nil { log.Fatal("Image not found in clipboard") @@ -48,7 +56,6 @@ func Open(file string, url, clip bool) TranslatorImage { var buf bytes.Buffer tee := io.TeeReader(bytes.NewReader(imgByte), &buf) - var err error img, _, err = image.Decode(tee) size = buf.Len() if err != nil {