From 7dc7e7a7663b76382bbcd907104277591286820c Mon Sep 17 00:00:00 2001 From: edm20627 Date: Thu, 25 Feb 2021 12:18:20 +0900 Subject: [PATCH 01/24] =?UTF-8?q?=E3=81=B2=E3=81=A8=E3=81=BE=E3=81=9A?= =?UTF-8?q?=E5=8B=95=E3=81=8F=E3=82=82=E3=81=AE=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai1/edm20627/go.mod | 3 ++ kadai1/edm20627/main.go | 107 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 110 insertions(+) create mode 100644 kadai1/edm20627/go.mod create mode 100644 kadai1/edm20627/main.go diff --git a/kadai1/edm20627/go.mod b/kadai1/edm20627/go.mod new file mode 100644 index 00000000..02e3b462 --- /dev/null +++ b/kadai1/edm20627/go.mod @@ -0,0 +1,3 @@ +module github.com/edm20627/gopherdojo-studyroom/kadai1/edm20627 + +go 1.15 diff --git a/kadai1/edm20627/main.go b/kadai1/edm20627/main.go new file mode 100644 index 00000000..7633ff66 --- /dev/null +++ b/kadai1/edm20627/main.go @@ -0,0 +1,107 @@ +package main + +import ( + "errors" + "flag" + "fmt" + "image" + "image/gif" + "image/jpeg" + "image/png" + "path/filepath" + "strings" + + "os" +) + +var supportedFormat = []string{"png", "jpg", "jpeg", "gif"} + +var from, to string + +func init() { + flag.StringVar(&from, "from", "jpg", "変更元") + flag.StringVar(&from, "f", "jpg", "変更元(short)") + flag.StringVar(&to, "to", "png", "変更先") + flag.StringVar(&to, "t", "png", "変更先(short)") +} + +func main() { + flag.Parse() + dirs := flag.Args() + + if !valid(from) || !valid(to) { + fmt.Fprintln(os.Stderr, "supported formt is "+strings.Join(supportedFormat, ", ")) + os.Exit(1) + } + + for _, dir := range dirs { + err := walk(dir) + if err != nil { + fmt.Fprintln(os.Stderr, err.Error()) + os.Exit(1) + } + } +} + +func walk(dir string) error { + err := filepath.Walk(dir, + func(path string, info os.FileInfo, err error) error { + if info == nil { + return errors.New(path + " is not directory") + } + if info.IsDir() || filepath.Ext(path)[1:] != from { + return nil + } + + err = imageConvert(path) + if err != nil { + return err + } + + return nil + }) + + if err != nil { + return err + } + return nil +} + +func imageConvert(path string) error { + f, err := os.Open(path) + if err != nil { + return err + } + defer f.Close() + + img, _, err := image.Decode(f) + if err != nil { + return err + } + + out, err := os.Create(path[:len(path)-len(filepath.Ext(path))] + "." + to) + if err != nil { + return err + } + defer out.Close() + + switch to { + case "png": + png.Encode(out, img) + case "jpg": + jpeg.Encode(out, img, nil) + case "gif": + gif.Encode(out, img, nil) + } + + return nil +} + +func valid(extension string) bool { + for _, v := range supportedFormat { + if v == extension { + return true + } + } + return false +} From 5aed38c41d662aa87bc8f074902f2b84be1a2ada Mon Sep 17 00:00:00 2001 From: edm20627 Date: Fri, 26 Feb 2021 01:45:41 +0900 Subject: [PATCH 02/24] =?UTF-8?q?=E3=83=A6=E3=83=BC=E3=82=B6=E5=AE=9A?= =?UTF-8?q?=E7=BE=A9=E5=9E=8B=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai1/edm20627/main.go | 100 ++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 44 deletions(-) diff --git a/kadai1/edm20627/main.go b/kadai1/edm20627/main.go index 7633ff66..8513bc7d 100644 --- a/kadai1/edm20627/main.go +++ b/kadai1/edm20627/main.go @@ -8,66 +8,50 @@ import ( "image/gif" "image/jpeg" "image/png" + "os" "path/filepath" "strings" - - "os" ) var supportedFormat = []string{"png", "jpg", "jpeg", "gif"} -var from, to string - -func init() { - flag.StringVar(&from, "from", "jpg", "変更元") - flag.StringVar(&from, "f", "jpg", "変更元(short)") - flag.StringVar(&to, "to", "png", "変更先") - flag.StringVar(&to, "t", "png", "変更先(short)") +type convertImage struct { + filepaths []string + from, to string } -func main() { - flag.Parse() - dirs := flag.Args() - - if !valid(from) || !valid(to) { - fmt.Fprintln(os.Stderr, "supported formt is "+strings.Join(supportedFormat, ", ")) - os.Exit(1) - } - +func (ci *convertImage) get(dirs []string) error { for _, dir := range dirs { - err := walk(dir) + err := filepath.Walk(dir, + func(path string, info os.FileInfo, err error) error { + if info == nil { + return errors.New(path + " is not directory") + } + if info.IsDir() || filepath.Ext(path)[1:] != ci.from { + return nil + } + ci.filepaths = append(ci.filepaths, path) + return nil + }) if err != nil { - fmt.Fprintln(os.Stderr, err.Error()) - os.Exit(1) + return err } + return nil } + return nil } -func walk(dir string) error { - err := filepath.Walk(dir, - func(path string, info os.FileInfo, err error) error { - if info == nil { - return errors.New(path + " is not directory") - } - if info.IsDir() || filepath.Ext(path)[1:] != from { - return nil - } - - err = imageConvert(path) - if err != nil { - return err - } - - return nil - }) - - if err != nil { - return err +func (ci *convertImage) convert() error { + for _, path := range ci.filepaths { + err := convert(path, ci.to) + if err != nil { + return err + } } return nil } -func imageConvert(path string) error { +func convert(path string, to string) error { f, err := os.Open(path) if err != nil { return err @@ -88,15 +72,43 @@ func imageConvert(path string) error { switch to { case "png": png.Encode(out, img) - case "jpg": + case "jpg", "jpeg": jpeg.Encode(out, img, nil) case "gif": gif.Encode(out, img, nil) } - return nil } +var ci = convertImage{} + +func init() { + flag.StringVar(&ci.from, "from", "jpg", "変更元") + flag.StringVar(&ci.from, "f", "jpg", "変更元(short)") + flag.StringVar(&ci.to, "to", "png", "変更先") + flag.StringVar(&ci.to, "t", "png", "変更先(short)") +} + +func main() { + flag.Parse() + dirs := flag.Args() + + if !valid(ci.from) || !valid(ci.to) { + fmt.Fprintln(os.Stderr, "supported formt is "+strings.Join(supportedFormat, ", ")) + os.Exit(1) + } + + err := ci.get(dirs) + if err != nil { + fmt.Fprintln(os.Stderr, err) + } + + err = ci.convert() + if err != nil { + fmt.Fprintln(os.Stderr, err) + } +} + func valid(extension string) bool { for _, v := range supportedFormat { if v == extension { From 9dc975548aee8f0c5684e62a812b1ac82bd34538 Mon Sep 17 00:00:00 2001 From: edm20627 Date: Fri, 26 Feb 2021 03:12:22 +0900 Subject: [PATCH 03/24] =?UTF-8?q?=E8=87=AA=E4=BD=9C=E3=83=91=E3=83=83?= =?UTF-8?q?=E3=82=B1=E3=83=BC=E3=82=B8=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai1/edm20627/imageconvert/imageconvert.go | 76 +++++++++++++++++ kadai1/edm20627/main.go | 88 ++------------------ 2 files changed, 85 insertions(+), 79 deletions(-) create mode 100644 kadai1/edm20627/imageconvert/imageconvert.go diff --git a/kadai1/edm20627/imageconvert/imageconvert.go b/kadai1/edm20627/imageconvert/imageconvert.go new file mode 100644 index 00000000..65ac6019 --- /dev/null +++ b/kadai1/edm20627/imageconvert/imageconvert.go @@ -0,0 +1,76 @@ +package imageconvert + +import ( + "errors" + "image" + "image/gif" + "image/jpeg" + "image/png" + "os" + "path/filepath" +) + +type ConvertImage struct { + filepaths []string + From, To string +} + +func (ci *ConvertImage) Get(dirs []string) error { + for _, dir := range dirs { + err := filepath.Walk(dir, + func(path string, info os.FileInfo, err error) error { + if info == nil { + return errors.New(path + " is not directory") + } + if info.IsDir() || filepath.Ext(path)[1:] != ci.From { + return nil + } + ci.filepaths = append(ci.filepaths, path) + return nil + }) + if err != nil { + return err + } + return nil + } + return nil +} + +func (ci *ConvertImage) Convert() error { + for _, path := range ci.filepaths { + err := convert(path, ci.To) + if err != nil { + return err + } + } + return nil +} + +func convert(path string, To string) error { + f, err := os.Open(path) + if err != nil { + return err + } + defer f.Close() + + img, _, err := image.Decode(f) + if err != nil { + return err + } + + out, err := os.Create(path[:len(path)-len(filepath.Ext(path))] + "." + To) + if err != nil { + return err + } + defer out.Close() + + switch To { + case "png": + png.Encode(out, img) + case "jpg", "jpeg": + jpeg.Encode(out, img, nil) + case "gif": + gif.Encode(out, img, nil) + } + return nil +} diff --git a/kadai1/edm20627/main.go b/kadai1/edm20627/main.go index 8513bc7d..27898b57 100644 --- a/kadai1/edm20627/main.go +++ b/kadai1/edm20627/main.go @@ -1,109 +1,39 @@ package main import ( - "errors" "flag" "fmt" - "image" - "image/gif" - "image/jpeg" - "image/png" "os" - "path/filepath" "strings" + "github.com/edm20627/gopherdojo-studyroom/kadai1/edm20627/imageconvert" ) var supportedFormat = []string{"png", "jpg", "jpeg", "gif"} -type convertImage struct { - filepaths []string - from, to string -} - -func (ci *convertImage) get(dirs []string) error { - for _, dir := range dirs { - err := filepath.Walk(dir, - func(path string, info os.FileInfo, err error) error { - if info == nil { - return errors.New(path + " is not directory") - } - if info.IsDir() || filepath.Ext(path)[1:] != ci.from { - return nil - } - ci.filepaths = append(ci.filepaths, path) - return nil - }) - if err != nil { - return err - } - return nil - } - return nil -} - -func (ci *convertImage) convert() error { - for _, path := range ci.filepaths { - err := convert(path, ci.to) - if err != nil { - return err - } - } - return nil -} - -func convert(path string, to string) error { - f, err := os.Open(path) - if err != nil { - return err - } - defer f.Close() - - img, _, err := image.Decode(f) - if err != nil { - return err - } - - out, err := os.Create(path[:len(path)-len(filepath.Ext(path))] + "." + to) - if err != nil { - return err - } - defer out.Close() - - switch to { - case "png": - png.Encode(out, img) - case "jpg", "jpeg": - jpeg.Encode(out, img, nil) - case "gif": - gif.Encode(out, img, nil) - } - return nil -} - -var ci = convertImage{} +var ci = imageconvert.ConvertImage{} func init() { - flag.StringVar(&ci.from, "from", "jpg", "変更元") - flag.StringVar(&ci.from, "f", "jpg", "変更元(short)") - flag.StringVar(&ci.to, "to", "png", "変更先") - flag.StringVar(&ci.to, "t", "png", "変更先(short)") + flag.StringVar(&ci.From, "from", "jpg", "変更元") + flag.StringVar(&ci.From, "f", "jpg", "変更元(short)") + flag.StringVar(&ci.To, "to", "png", "変更先") + flag.StringVar(&ci.To, "t", "png", "変更先(short)") } func main() { flag.Parse() dirs := flag.Args() - if !valid(ci.from) || !valid(ci.to) { + if !valid(ci.From) || !valid(ci.To) { fmt.Fprintln(os.Stderr, "supported formt is "+strings.Join(supportedFormat, ", ")) os.Exit(1) } - err := ci.get(dirs) + err := ci.Get(dirs) if err != nil { fmt.Fprintln(os.Stderr, err) } - err = ci.convert() + err = ci.Convert() if err != nil { fmt.Fprintln(os.Stderr, err) } From 7d5d81e4abca64390c571eff1a7c0874da93196d Mon Sep 17 00:00:00 2001 From: edm20627 Date: Fri, 26 Feb 2021 04:05:21 +0900 Subject: [PATCH 04/24] =?UTF-8?q?vlid=E9=96=A2=E6=95=B0=E3=82=92=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai1/edm20627/imageconvert/imageconvert.go | 16 ++++++++++++++++ kadai1/edm20627/main.go | 20 +++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/kadai1/edm20627/imageconvert/imageconvert.go b/kadai1/edm20627/imageconvert/imageconvert.go index 65ac6019..8e57c38b 100644 --- a/kadai1/edm20627/imageconvert/imageconvert.go +++ b/kadai1/edm20627/imageconvert/imageconvert.go @@ -10,6 +10,8 @@ import ( "path/filepath" ) +var SupportedFormat = []string{"png", "jpg", "jpeg", "gif"} + type ConvertImage struct { filepaths []string From, To string @@ -19,6 +21,7 @@ func (ci *ConvertImage) Get(dirs []string) error { for _, dir := range dirs { err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + if info == nil { return errors.New(path + " is not directory") } @@ -46,6 +49,19 @@ func (ci *ConvertImage) Convert() error { return nil } +func (ci *ConvertImage) Valid() bool { + for _, v := range SupportedFormat { + if v == ci.From { + for _, v := range SupportedFormat { + if v == ci.To { + return true + } + } + } + } + return false +} + func convert(path string, To string) error { f, err := os.Open(path) if err != nil { diff --git a/kadai1/edm20627/main.go b/kadai1/edm20627/main.go index 27898b57..a719f783 100644 --- a/kadai1/edm20627/main.go +++ b/kadai1/edm20627/main.go @@ -5,17 +5,16 @@ import ( "fmt" "os" "strings" + "github.com/edm20627/gopherdojo-studyroom/kadai1/edm20627/imageconvert" ) -var supportedFormat = []string{"png", "jpg", "jpeg", "gif"} - var ci = imageconvert.ConvertImage{} func init() { - flag.StringVar(&ci.From, "from", "jpg", "変更元") + flag.StringVar(&ci.From, "-from", "jpg", "変更元") flag.StringVar(&ci.From, "f", "jpg", "変更元(short)") - flag.StringVar(&ci.To, "to", "png", "変更先") + flag.StringVar(&ci.To, "-to", "png", "変更先") flag.StringVar(&ci.To, "t", "png", "変更先(short)") } @@ -23,8 +22,8 @@ func main() { flag.Parse() dirs := flag.Args() - if !valid(ci.From) || !valid(ci.To) { - fmt.Fprintln(os.Stderr, "supported formt is "+strings.Join(supportedFormat, ", ")) + if !ci.Valid() { + fmt.Fprintln(os.Stderr, "supported formt is "+strings.Join(imageconvert.SupportedFormat, ", ")) os.Exit(1) } @@ -38,12 +37,3 @@ func main() { fmt.Fprintln(os.Stderr, err) } } - -func valid(extension string) bool { - for _, v := range supportedFormat { - if v == extension { - return true - } - } - return false -} From 7776099779dd608ff046a3f2320983623e7210f1 Mon Sep 17 00:00:00 2001 From: edm20627 Date: Fri, 26 Feb 2021 04:23:47 +0900 Subject: [PATCH 05/24] =?UTF-8?q?=E5=BE=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai1/edm20627/imageconvert/imageconvert.go | 4 +--- kadai1/edm20627/main.go | 2 ++ 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kadai1/edm20627/imageconvert/imageconvert.go b/kadai1/edm20627/imageconvert/imageconvert.go index 8e57c38b..8794eff8 100644 --- a/kadai1/edm20627/imageconvert/imageconvert.go +++ b/kadai1/edm20627/imageconvert/imageconvert.go @@ -21,7 +21,6 @@ func (ci *ConvertImage) Get(dirs []string) error { for _, dir := range dirs { err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { - if info == nil { return errors.New(path + " is not directory") } @@ -34,7 +33,6 @@ func (ci *ConvertImage) Get(dirs []string) error { if err != nil { return err } - return nil } return nil } @@ -74,7 +72,7 @@ func convert(path string, To string) error { return err } - out, err := os.Create(path[:len(path)-len(filepath.Ext(path))] + "." + To) + out, err := os.Create(path[:len(path)-len(filepath.Ext(path))+1] + To) if err != nil { return err } diff --git a/kadai1/edm20627/main.go b/kadai1/edm20627/main.go index a719f783..c9b89e45 100644 --- a/kadai1/edm20627/main.go +++ b/kadai1/edm20627/main.go @@ -30,10 +30,12 @@ func main() { err := ci.Get(dirs) if err != nil { fmt.Fprintln(os.Stderr, err) + os.Exit(1) } err = ci.Convert() if err != nil { fmt.Fprintln(os.Stderr, err) + os.Exit(1) } } From a504b57d3a7f1dbc26fe9d59eae876e3ac13c7e1 Mon Sep 17 00:00:00 2001 From: edm20627 Date: Fri, 26 Feb 2021 04:26:20 +0900 Subject: [PATCH 06/24] =?UTF-8?q?=E7=94=BB=E5=83=8F=E5=A4=89=E6=8F=9B?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=81=AE=E3=82=A8=E3=83=A9=E3=83=BC=E3=83=8F?= =?UTF-8?q?=E3=83=B3=E3=83=89=E3=83=AA=E3=83=B3=E3=82=B0=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai1/edm20627/imageconvert/imageconvert.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/kadai1/edm20627/imageconvert/imageconvert.go b/kadai1/edm20627/imageconvert/imageconvert.go index 8794eff8..42125d34 100644 --- a/kadai1/edm20627/imageconvert/imageconvert.go +++ b/kadai1/edm20627/imageconvert/imageconvert.go @@ -80,11 +80,17 @@ func convert(path string, To string) error { switch To { case "png": - png.Encode(out, img) + if err := png.Encode(out, img); err != nil { + return err + } case "jpg", "jpeg": - jpeg.Encode(out, img, nil) + if err := jpeg.Encode(out, img, nil); err != nil { + return err + } case "gif": - gif.Encode(out, img, nil) + if err := gif.Encode(out, img, nil); err != nil { + return err + } } return nil } From 44bbfd1b62726dff7ebb3c248d017e1d24a37e0e Mon Sep 17 00:00:00 2001 From: edm20627 Date: Fri, 26 Feb 2021 05:00:58 +0900 Subject: [PATCH 07/24] =?UTF-8?q?=E5=89=8A=E9=99=A4=E3=83=95=E3=83=A9?= =?UTF-8?q?=E3=82=B0=E3=81=AE=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai1/edm20627/imageconvert/imageconvert.go | 20 ++++++++++++++------ kadai1/edm20627/main.go | 2 ++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/kadai1/edm20627/imageconvert/imageconvert.go b/kadai1/edm20627/imageconvert/imageconvert.go index 42125d34..97da376d 100644 --- a/kadai1/edm20627/imageconvert/imageconvert.go +++ b/kadai1/edm20627/imageconvert/imageconvert.go @@ -13,8 +13,9 @@ import ( var SupportedFormat = []string{"png", "jpg", "jpeg", "gif"} type ConvertImage struct { - filepaths []string - From, To string + filepaths []string + From, To string + DeleteOption bool } func (ci *ConvertImage) Get(dirs []string) error { @@ -39,7 +40,7 @@ func (ci *ConvertImage) Get(dirs []string) error { func (ci *ConvertImage) Convert() error { for _, path := range ci.filepaths { - err := convert(path, ci.To) + err := convert(path, ci.To, ci.DeleteOption) if err != nil { return err } @@ -60,7 +61,7 @@ func (ci *ConvertImage) Valid() bool { return false } -func convert(path string, To string) error { +func convert(path string, to string, deleteOption bool) error { f, err := os.Open(path) if err != nil { return err @@ -72,13 +73,13 @@ func convert(path string, To string) error { return err } - out, err := os.Create(path[:len(path)-len(filepath.Ext(path))+1] + To) + out, err := os.Create(path[:len(path)-len(filepath.Ext(path))+1] + to) if err != nil { return err } defer out.Close() - switch To { + switch to { case "png": if err := png.Encode(out, img); err != nil { return err @@ -92,5 +93,12 @@ func convert(path string, To string) error { return err } } + + if deleteOption { + if err := os.Remove(path); err != nil { + return err + } + } + return nil } diff --git a/kadai1/edm20627/main.go b/kadai1/edm20627/main.go index c9b89e45..4536126e 100644 --- a/kadai1/edm20627/main.go +++ b/kadai1/edm20627/main.go @@ -16,6 +16,8 @@ func init() { flag.StringVar(&ci.From, "f", "jpg", "変更元(short)") flag.StringVar(&ci.To, "-to", "png", "変更先") flag.StringVar(&ci.To, "t", "png", "変更先(short)") + flag.BoolVar(&ci.DeleteOption, "-delete", false, "削除フラグ") + flag.BoolVar(&ci.DeleteOption, "d", false, "削除フラグ(short)") } func main() { From 87c6eb376ef264b6776be9bff75b8c9424687e76 Mon Sep 17 00:00:00 2001 From: edm20627 Date: Fri, 26 Feb 2021 05:36:07 +0900 Subject: [PATCH 08/24] =?UTF-8?q?GoDoc=E3=82=92=E7=94=9F=E6=88=90=E3=81=99?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai1/edm20627/go.mod | 2 ++ kadai1/edm20627/go.sum | 28 ++++++++++++++++++++ kadai1/edm20627/imageconvert/imageconvert.go | 4 +++ kadai1/edm20627/main.go | 12 ++++----- 4 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 kadai1/edm20627/go.sum diff --git a/kadai1/edm20627/go.mod b/kadai1/edm20627/go.mod index 02e3b462..2c8176d4 100644 --- a/kadai1/edm20627/go.mod +++ b/kadai1/edm20627/go.mod @@ -1,3 +1,5 @@ module github.com/edm20627/gopherdojo-studyroom/kadai1/edm20627 go 1.15 + +require golang.org/x/tools v0.1.0 // indirect diff --git a/kadai1/edm20627/go.sum b/kadai1/edm20627/go.sum new file mode 100644 index 00000000..e3951444 --- /dev/null +++ b/kadai1/edm20627/go.sum @@ -0,0 +1,28 @@ +github.com/edm20627/gopherdojo-studyroom v0.0.0-20200808023015-dd3cfe05cf7a h1:qrHQJOIqb8bC1Ulkv5H6eGp3DZgRA93eLUJr6XK/Gjk= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k= +golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= +golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/kadai1/edm20627/imageconvert/imageconvert.go b/kadai1/edm20627/imageconvert/imageconvert.go index 97da376d..f8817128 100644 --- a/kadai1/edm20627/imageconvert/imageconvert.go +++ b/kadai1/edm20627/imageconvert/imageconvert.go @@ -10,6 +10,7 @@ import ( "path/filepath" ) +// Supported extensions. var SupportedFormat = []string{"png", "jpg", "jpeg", "gif"} type ConvertImage struct { @@ -18,6 +19,7 @@ type ConvertImage struct { DeleteOption bool } +// Get the target files for image conversion. func (ci *ConvertImage) Get(dirs []string) error { for _, dir := range dirs { err := filepath.Walk(dir, @@ -38,6 +40,7 @@ func (ci *ConvertImage) Get(dirs []string) error { return nil } +// Perform image conversion. func (ci *ConvertImage) Convert() error { for _, path := range ci.filepaths { err := convert(path, ci.To, ci.DeleteOption) @@ -48,6 +51,7 @@ func (ci *ConvertImage) Convert() error { return nil } +// Check for supported extensions. func (ci *ConvertImage) Valid() bool { for _, v := range SupportedFormat { if v == ci.From { diff --git a/kadai1/edm20627/main.go b/kadai1/edm20627/main.go index 4536126e..407d2409 100644 --- a/kadai1/edm20627/main.go +++ b/kadai1/edm20627/main.go @@ -12,12 +12,12 @@ import ( var ci = imageconvert.ConvertImage{} func init() { - flag.StringVar(&ci.From, "-from", "jpg", "変更元") - flag.StringVar(&ci.From, "f", "jpg", "変更元(short)") - flag.StringVar(&ci.To, "-to", "png", "変更先") - flag.StringVar(&ci.To, "t", "png", "変更先(short)") - flag.BoolVar(&ci.DeleteOption, "-delete", false, "削除フラグ") - flag.BoolVar(&ci.DeleteOption, "d", false, "削除フラグ(short)") + flag.StringVar(&ci.From, "-from", "jpg", "Specify the image format before conversion") + flag.StringVar(&ci.From, "f", "jpg", "Specify the image format before conversion (short)") + flag.StringVar(&ci.To, "-to", "png", "Specify the converted image format") + flag.StringVar(&ci.To, "t", "png", "Specify the converted image format (short)") + flag.BoolVar(&ci.DeleteOption, "-delete", false, "Delete the image before conversion") + flag.BoolVar(&ci.DeleteOption, "d", false, "Delete the image before conversion (short)") } func main() { From 44e95d364d308fec5e6d4bc20b85ae1748b11c95 Mon Sep 17 00:00:00 2001 From: edm20627 Date: Fri, 26 Feb 2021 05:43:50 +0900 Subject: [PATCH 09/24] =?UTF-8?q?=E3=82=B5=E3=83=B3=E3=83=97=E3=83=AB?= =?UTF-8?q?=E7=94=BB=E5=83=8F=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai1/edm20627/sample_image/.DS_Store | Bin 0 -> 8196 bytes kadai1/edm20627/sample_image/hoge/.DS_Store | Bin 0 -> 6148 bytes kadai1/edm20627/sample_image/hoge/sample3.png | Bin 0 -> 1342 bytes kadai1/edm20627/sample_image/hoge/sample4.png | Bin 0 -> 2294 bytes kadai1/edm20627/sample_image/sample.jpg | Bin 0 -> 2539 bytes kadai1/edm20627/sample_image/sample2.jpg | Bin 0 -> 5682 bytes 6 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 kadai1/edm20627/sample_image/.DS_Store create mode 100644 kadai1/edm20627/sample_image/hoge/.DS_Store create mode 100644 kadai1/edm20627/sample_image/hoge/sample3.png create mode 100644 kadai1/edm20627/sample_image/hoge/sample4.png create mode 100644 kadai1/edm20627/sample_image/sample.jpg create mode 100644 kadai1/edm20627/sample_image/sample2.jpg diff --git a/kadai1/edm20627/sample_image/.DS_Store b/kadai1/edm20627/sample_image/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..6e722ea79846a21c0f5fa61c81690b3f04c02911 GIT binary patch literal 8196 zcmeHMU2GLa6rS(4h1mt#r4(797jCRotOZ(V3-S|gf1v_GxTP(nTJF8OwkzA+dUx+F zP^%^Ci!sK(=mX;4gD*yn4;sb9sKH2L;)6C(jPPROi$3sT6nW4yJKLr$@WO+^u#?Q3 zIp@ro*>mPQJ9qXn#?X>C>KW4+W1Om>+5&2>QG{O9t4b`Cln@2kv&^VBlCj+k@!woE zIub+?h$0Y0Ac{Z~fhYnuLj>r|7KLB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BE{vkmA Tc#Y2g;8$vN{s$nu1)F~XD#Rz^ literal 0 HcmV?d00001 diff --git a/kadai1/edm20627/sample_image/hoge/.DS_Store b/kadai1/edm20627/sample_image/hoge/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..0c5cb0d66222f556bb6347da6a862e9cc33b766a GIT binary patch literal 6148 zcmeH~Jx{|h5QfjCLs6HGjQIl)+5y(6DjQ;{VC5@OC{S88>A;qs&U3a^wMxr~Ds(5^ zz4rOeXTO%>SVY`-oexC@BGN+@JExdEqT{M9=|qpB^K*PkAtSkvrF^xb&2fwj=-Kt9 zl4qH7YTM^mF6)=ubycs3sAMYN*qZa5ODYetAa+f=z?;g1{2EQ=o_--K?^VwS`i556 z8RHdWuV5iL*(14>E9^C%k~x<|X?9Ng9o_FeXO^1kIcr)GweV}wN;x`{;okYT_xMQE zoY<0TDK!_d^&1y=k&6Rt9pmBJnv4Nsz!*5d0C%=ZuOHB?F<=ZB0~-eP`;efDS;Quw z|8!vd69DYu_Cj0V5}K1l%px`c89`h~1w*QfPYf5*@h34Zi`WDV>Ee84=82VEe4#jB z9e?7(#bp7_8Ux0_E(0f_JJ9?8=J5M}H_3X&fHCl|7;xRmbTVd3@osHxPVd?TeL__< mt_iqFq2aG$V)ZIML%rZnv;k%jn}B!_`w{Rom@x+alz|_M8%iqx literal 0 HcmV?d00001 diff --git a/kadai1/edm20627/sample_image/hoge/sample3.png b/kadai1/edm20627/sample_image/hoge/sample3.png new file mode 100644 index 0000000000000000000000000000000000000000..02908b23efaf7d0ee46c3703acdb1b1be8fd9b50 GIT binary patch literal 1342 zcmZ{kX;9J$7{>o;t($I}Www>I#dPd!jRlsunr0v*hMFSck@tP9CzyDm1|BJyx25HJ zn8V z)4$Kp(vmGV9@#CyURS6A6adN-<#z1%N&Fc{B-#J~f-e9-1PK7PB&UcO00;mBz?>Zb zXk-GwZ@$^J#+m@IXVgd^gV4I=Tk*Q(+qZA7?umZ5^jkXq@f7NpKF<2ONGKHbvnL)s zE=ArU2n50hNh>J zh%yLXSXh0Y^Y(QmYj}hQgX3)M;|RgoZXSu+P`^fIPjN}Z`^N5|knHX49UHq?Z@*M~ z$A|Z9qJ8|*8kxO({>sjdcx-(7ZB3hn6?uX?8~GqFij>dc%+%JkYs38Ex&f2C`K;_J zH_yj$@x`mF>;Cu*TtMc^%G%KUD>>91B+*C!|E{qPxsLtl+eh&?@{5mC9_JtNMp6jQTE zL*p>UyH1_k_;Jqk(vsj~8ygD8EibQ4Ow1-F(+djg2L`$3mLzh_3s!5N?wvsP0QXgS zGX@*^w|9!CcQV>EB005ecXu}+@QDdFf)JcFG&K2=&P3?mr_$bYzs_xK@3?y=wRa4{ z5cm@6dk5!uti^-Gq?d(7jD^KjidQC8(tteOrO$+bN?%>?%F|4h5T7dt|Ec5kl&V7?V;AxZf+q)ZZ)e~WtbkZZqW%m z?0BdSl-_bt#yd8v`aJE|1f_#M+ngFlwWeP4wuV`Hb&+-ahhwVQ1|uwK&9z}U$kl$Q zYLMV_UZ#g4ME}#p1l{OG7E)`4Q^Jrp@tHr)?CR@Vk-9=AC^9{(o^vkbD=YT}!7U3qIrge~PBHl-X=banlcZ*Et+!v)4BMVo@viTzPC zM3J1Lc04*`gL6z$zVmp5Io`=0@2uhI?<@hJ0#<=2gH@DOR54&R4KPGQ<@zPCx&|10 h@K1}H{{*~zoZMZ4{yz|opZNX&0X>8voDQ>#`WGexrZfNm literal 0 HcmV?d00001 diff --git a/kadai1/edm20627/sample_image/hoge/sample4.png b/kadai1/edm20627/sample_image/hoge/sample4.png new file mode 100644 index 0000000000000000000000000000000000000000..fc271cd818acd70231a44ce50f3df900ef8a2d0e GIT binary patch literal 2294 zcma)8S5Om(7LBs2K6gRaMp?Uy4i*SS5KxpB2uPLQq=p{Egx*^aAw*i}O-djkAcT(e z-U32Gq_%YIZT0I3zip$cs{sJ`-Uk4J!~d%fUIhR=fB?XnB>*6k z0s!#7%c$3R4gj2v(0;9_{NmL+v$v5cX$0cX>gO z@9!Vx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R-d_BWvS~x@hF~)uJGqg1x-x7y%lGAu? zS9J9Q*?=C~U|2NWQJVxDm-u<$R3THNLIw#AZTlRjm|8eSwrf88g|VuThe@L}RoU=~-0o zvRHU7n_|SN)>H)yRJSX2FRxxGKgU95_{vf<{Wgtqq)knUzAlu=?5^1M8ffu4kTg^X$$HQJ|c8|M*Ra zbNol`;{xzjT!bQSZR3JpBwONq&Ai`^-Bo%74e@$9qMF=t89k=cg;-;%bAeDB$I-7^ pTN!l9>I(ei(Pzmaef}2}hf*7CF<#~tHKl*$bnw3i4HNF?zXMfLj*9>Q literal 0 HcmV?d00001 diff --git a/kadai1/edm20627/sample_image/sample2.jpg b/kadai1/edm20627/sample_image/sample2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..839329053ebba54444d49e370f4f7c4c952871d8 GIT binary patch literal 5682 zcmeHLcQhQ%w_g^E2oVv%B6>tf1kpvJN6SX^mSiK!VzE|RLP$iET_voN5Z$WLyAWk{ zR*&9AS)I-D#ZTV*y>s4q|GmH8`^?Opa_{}zd*+-uXJ*dF&*uPFo@i)m04OLZ09qFX za6So81yE8@{H^~6kQ(?GG*nbTY7h+w^taK{U819nrzG6Un^ z@n4d^?ti^5Dg!Nu_OHeN4(Ck(W?H~8;22232cTr805VgYw*t5>QUw43zzg|bprrxP zQBqM;058-JuK+0iCQC_038JP2UYJk-D1lVeG$2}Lx~se_67<*j9^Hpr=iq%z?v{l@*;chd}gs&z%gb~>8`Q!?s1c4!4lD*6CHDpX?RR6n`8(4V`VF4t_n{Zb>` zs~<2g+M~z19q~vo=n9j($R}cVemq-*{+Mi75I*|+Y=|@TQEnsJ?32~KJ4v&>S=zxt{FBkpfU+tuXeP2 z8P&e(*`~*jLM6>97y0o}n5AOFFY^moI4X^Y_4K82rT;Eo?}Cky%d~zZO$DSuW_BOM zMsH#*Vc!|@Dm!hwzvTpFYZprDh>0dk0w;i(Xc>2k{cg?FUZeJ7ET_`hjA(23gRG4D z78Ab7NsaOB9QeoExJrj3#g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mRpXI&qe;^%fmJ>Lpeef7|8}I^C z{YUBhai3Re&hJ(9T&CCwEb_sU3>L>;$PfZ^-Xkmg7I;V!fhvDyJe_LeWa4o#qONVM zGPAC*FVs(VSYeK|pJ8&192g~-c6jW!ZsTcD{GX!R&jH&s8sPa3aiU;0uZe5*FFPf& p*<$t^K0cWSHB^63hC`(K3pMpo Date: Fri, 26 Feb 2021 11:06:37 +0900 Subject: [PATCH 10/24] =?UTF-8?q?README.md=20=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai1/edm20627/README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 kadai1/edm20627/README.md diff --git a/kadai1/edm20627/README.md b/kadai1/edm20627/README.md new file mode 100644 index 00000000..789cb3e5 --- /dev/null +++ b/kadai1/edm20627/README.md @@ -0,0 +1,12 @@ +# 画像変換コマンド +指定ディレクトリ以下の画像ファイルを変換します。 + +## 使用方法 + +`cmd --from jpg --to png ディレクトリ` + +## オプション + +* `--from(-f)` 変換対象の画像形式(デフォルト: jpg) +* `--to(-t)` 変換後の画像形式(デフォルト: png) +* `--delete(-d)` 変換前の画像を削除(デフォルト: 無効) From 49c5e89e11f96d2f85eb987453eed7b8067e1a1d Mon Sep 17 00:00:00 2001 From: edm20627 Date: Fri, 26 Feb 2021 23:46:18 +0900 Subject: [PATCH 11/24] .gitignore --- kadai1/edm20627/sample_image/.DS_Store | Bin 8196 -> 0 bytes kadai1/edm20627/sample_image/hoge/.DS_Store | Bin 6148 -> 0 bytes kadai1/edm20627/sample_image/hoge/.gitignore | 17 +++++++++++++++++ 3 files changed, 17 insertions(+) delete mode 100644 kadai1/edm20627/sample_image/.DS_Store delete mode 100644 kadai1/edm20627/sample_image/hoge/.DS_Store create mode 100644 kadai1/edm20627/sample_image/hoge/.gitignore diff --git a/kadai1/edm20627/sample_image/.DS_Store b/kadai1/edm20627/sample_image/.DS_Store deleted file mode 100644 index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z$*k|l4`<9(&Kd}q!BKw8?&i-J3vcK46#88A1%)=5?B92w4!A3No37fDD z?dZTRbmD&Wpcj2Oj5Hp`Q4GUD0gqz>C-F31#7lS?ui$OGk56z0pW-aO!q+&5@9{G( z;36*JGXBPuSZS;*rpKyd>*OQHrt+kFHo9W#iJzGg;itTqf31{=w|DHkIa1>MLXiZE z%a>FvT_rN3Y3q(@2uZ|Efovvt1H8`K(*UnQe$2%hrONUZE7kZx0>bs_&Lg->_U@W^T#HebNp{`(xT+OV4k>}{#u{P~GMhH5s#Z+d zBz4L)^7GNcodl7`BE{vkmA Tc#Y2g;8$vN{s$nu1)F~XD#Rz^ diff --git a/kadai1/edm20627/sample_image/hoge/.DS_Store b/kadai1/edm20627/sample_image/hoge/.DS_Store deleted file mode 100644 index 0c5cb0d66222f556bb6347da6a862e9cc33b766a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeH~Jx{|h5QfjCLs6HGjQIl)+5y(6DjQ;{VC5@OC{S88>A;qs&U3a^wMxr~Ds(5^ zz4rOeXTO%>SVY`-oexC@BGN+@JExdEqT{M9=|qpB^K*PkAtSkvrF^xb&2fwj=-Kt9 zl4qH7YTM^mF6)=ubycs3sAMYN*qZa5ODYetAa+f=z?;g1{2EQ=o_--K?^VwS`i556 z8RHdWuV5iL*(14>E9^C%k~x<|X?9Ng9o_FeXO^1kIcr)GweV}wN;x`{;okYT_xMQE zoY<0TDK!_d^&1y=k&6Rt9pmBJnv4Nsz!*5d0C%=ZuOHB?F<=ZB0~-eP`;efDS;Quw z|8!vd69DYu_Cj0V5}K1l%px`c89`h~1w*QfPYf5*@h34Zi`WDV>Ee84=82VEe4#jB z9e?7(#bp7_8Ux0_E(0f_JJ9?8=J5M}H_3X&fHCl|7;xRmbTVd3@osHxPVd?TeL__< mt_iqFq2aG$V)ZIML%rZnv;k%jn}B!_`w{Rom@x+alz|_M8%iqx diff --git a/kadai1/edm20627/sample_image/hoge/.gitignore b/kadai1/edm20627/sample_image/hoge/.gitignore new file mode 100644 index 00000000..6ecd33cb --- /dev/null +++ b/kadai1/edm20627/sample_image/hoge/.gitignore @@ -0,0 +1,17 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +.DS_store From 74fabfab6a6df839ea39af341855cd1c103f59d6 Mon Sep 17 00:00:00 2001 From: edm20627 Date: Fri, 26 Feb 2021 23:50:32 +0900 Subject: [PATCH 12/24] =?UTF-8?q?go=20mod=20tidy=20=E5=AE=9F=E8=A1=8C'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai1/edm20627/go.mod | 2 -- kadai1/edm20627/go.sum | 28 ---------------------------- 2 files changed, 30 deletions(-) delete mode 100644 kadai1/edm20627/go.sum diff --git a/kadai1/edm20627/go.mod b/kadai1/edm20627/go.mod index 2c8176d4..02e3b462 100644 --- a/kadai1/edm20627/go.mod +++ b/kadai1/edm20627/go.mod @@ -1,5 +1,3 @@ module github.com/edm20627/gopherdojo-studyroom/kadai1/edm20627 go 1.15 - -require golang.org/x/tools v0.1.0 // indirect diff --git a/kadai1/edm20627/go.sum b/kadai1/edm20627/go.sum deleted file mode 100644 index e3951444..00000000 --- a/kadai1/edm20627/go.sum +++ /dev/null @@ -1,28 +0,0 @@ -github.com/edm20627/gopherdojo-studyroom v0.0.0-20200808023015-dd3cfe05cf7a h1:qrHQJOIqb8bC1Ulkv5H6eGp3DZgRA93eLUJr6XK/Gjk= -github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4= -golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20201021035429-f5854403a974 h1:IX6qOQeG5uLjB/hjjwjedwfjND0hgjPMMyO1RoIXQNI= -golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k= -golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.0 h1:po9/4sTYwZU9lPhi1tOrb4hCv3qrhiQ77LZfGa2OjwY= -golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From f4be072568e42dbcbae9b80f275869d03336c7a9 Mon Sep 17 00:00:00 2001 From: edm20627 Date: Wed, 7 Apr 2021 14:55:26 +0900 Subject: [PATCH 13/24] =?UTF-8?q?.gitignore=E3=81=AE=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai1/edm20627/{sample_image/hoge => }/.gitignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename kadai1/edm20627/{sample_image/hoge => }/.gitignore (100%) diff --git a/kadai1/edm20627/sample_image/hoge/.gitignore b/kadai1/edm20627/.gitignore similarity index 100% rename from kadai1/edm20627/sample_image/hoge/.gitignore rename to kadai1/edm20627/.gitignore From 183f52ff23d7838fba5d3b909d7a7c7dea9d6ae4 Mon Sep 17 00:00:00 2001 From: edm20627 Date: Wed, 7 Apr 2021 15:00:19 +0900 Subject: [PATCH 14/24] =?UTF-8?q?=E8=AA=B2=E9=A1=8C1=E3=82=92=E3=82=B3?= =?UTF-8?q?=E3=83=94=E3=83=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/edm20627/.gitignore | 17 +++ kadai2/edm20627/README.md | 12 ++ kadai2/edm20627/go.mod | 3 + kadai2/edm20627/imageconvert/imageconvert.go | 108 ++++++++++++++++++ kadai2/edm20627/main.go | 43 +++++++ kadai2/edm20627/sample_image/hoge/sample3.png | Bin 0 -> 1342 bytes kadai2/edm20627/sample_image/hoge/sample4.png | Bin 0 -> 2294 bytes kadai2/edm20627/sample_image/sample.jpg | Bin 0 -> 2539 bytes kadai2/edm20627/sample_image/sample2.jpg | Bin 0 -> 5682 bytes 9 files changed, 183 insertions(+) create mode 100644 kadai2/edm20627/.gitignore create mode 100644 kadai2/edm20627/README.md create mode 100644 kadai2/edm20627/go.mod create mode 100644 kadai2/edm20627/imageconvert/imageconvert.go create mode 100644 kadai2/edm20627/main.go create mode 100644 kadai2/edm20627/sample_image/hoge/sample3.png create mode 100644 kadai2/edm20627/sample_image/hoge/sample4.png create mode 100644 kadai2/edm20627/sample_image/sample.jpg create mode 100644 kadai2/edm20627/sample_image/sample2.jpg diff --git a/kadai2/edm20627/.gitignore b/kadai2/edm20627/.gitignore new file mode 100644 index 00000000..6ecd33cb --- /dev/null +++ b/kadai2/edm20627/.gitignore @@ -0,0 +1,17 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +.DS_store diff --git a/kadai2/edm20627/README.md b/kadai2/edm20627/README.md new file mode 100644 index 00000000..789cb3e5 --- /dev/null +++ b/kadai2/edm20627/README.md @@ -0,0 +1,12 @@ +# 画像変換コマンド +指定ディレクトリ以下の画像ファイルを変換します。 + +## 使用方法 + +`cmd --from jpg --to png ディレクトリ` + +## オプション + +* `--from(-f)` 変換対象の画像形式(デフォルト: jpg) +* `--to(-t)` 変換後の画像形式(デフォルト: png) +* `--delete(-d)` 変換前の画像を削除(デフォルト: 無効) diff --git a/kadai2/edm20627/go.mod b/kadai2/edm20627/go.mod new file mode 100644 index 00000000..02e3b462 --- /dev/null +++ b/kadai2/edm20627/go.mod @@ -0,0 +1,3 @@ +module github.com/edm20627/gopherdojo-studyroom/kadai1/edm20627 + +go 1.15 diff --git a/kadai2/edm20627/imageconvert/imageconvert.go b/kadai2/edm20627/imageconvert/imageconvert.go new file mode 100644 index 00000000..f8817128 --- /dev/null +++ b/kadai2/edm20627/imageconvert/imageconvert.go @@ -0,0 +1,108 @@ +package imageconvert + +import ( + "errors" + "image" + "image/gif" + "image/jpeg" + "image/png" + "os" + "path/filepath" +) + +// Supported extensions. +var SupportedFormat = []string{"png", "jpg", "jpeg", "gif"} + +type ConvertImage struct { + filepaths []string + From, To string + DeleteOption bool +} + +// Get the target files for image conversion. +func (ci *ConvertImage) Get(dirs []string) error { + for _, dir := range dirs { + err := filepath.Walk(dir, + func(path string, info os.FileInfo, err error) error { + if info == nil { + return errors.New(path + " is not directory") + } + if info.IsDir() || filepath.Ext(path)[1:] != ci.From { + return nil + } + ci.filepaths = append(ci.filepaths, path) + return nil + }) + if err != nil { + return err + } + } + return nil +} + +// Perform image conversion. +func (ci *ConvertImage) Convert() error { + for _, path := range ci.filepaths { + err := convert(path, ci.To, ci.DeleteOption) + if err != nil { + return err + } + } + return nil +} + +// Check for supported extensions. +func (ci *ConvertImage) Valid() bool { + for _, v := range SupportedFormat { + if v == ci.From { + for _, v := range SupportedFormat { + if v == ci.To { + return true + } + } + } + } + return false +} + +func convert(path string, to string, deleteOption bool) error { + f, err := os.Open(path) + if err != nil { + return err + } + defer f.Close() + + img, _, err := image.Decode(f) + if err != nil { + return err + } + + out, err := os.Create(path[:len(path)-len(filepath.Ext(path))+1] + to) + if err != nil { + return err + } + defer out.Close() + + switch to { + case "png": + if err := png.Encode(out, img); err != nil { + return err + } + case "jpg", "jpeg": + if err := jpeg.Encode(out, img, nil); err != nil { + return err + } + case "gif": + if err := gif.Encode(out, img, nil); err != nil { + return err + } + } + + if deleteOption { + if err := os.Remove(path); err != nil { + return err + } + } + + return nil +} diff --git a/kadai2/edm20627/main.go b/kadai2/edm20627/main.go new file mode 100644 index 00000000..407d2409 --- /dev/null +++ b/kadai2/edm20627/main.go @@ -0,0 +1,43 @@ +package main + +import ( + "flag" + "fmt" + "os" + "strings" + + "github.com/edm20627/gopherdojo-studyroom/kadai1/edm20627/imageconvert" +) + +var ci = imageconvert.ConvertImage{} + +func init() { + flag.StringVar(&ci.From, "-from", "jpg", "Specify the image format before conversion") + flag.StringVar(&ci.From, "f", "jpg", "Specify the image format before conversion (short)") + flag.StringVar(&ci.To, "-to", "png", "Specify the converted image format") + flag.StringVar(&ci.To, "t", "png", "Specify the converted image format (short)") + flag.BoolVar(&ci.DeleteOption, "-delete", false, "Delete the image before conversion") + flag.BoolVar(&ci.DeleteOption, "d", false, "Delete the image before conversion (short)") +} + +func main() { + flag.Parse() + dirs := flag.Args() + + if !ci.Valid() { + fmt.Fprintln(os.Stderr, "supported formt is "+strings.Join(imageconvert.SupportedFormat, ", ")) + os.Exit(1) + } + + err := ci.Get(dirs) + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + + err = ci.Convert() + if err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} diff --git a/kadai2/edm20627/sample_image/hoge/sample3.png b/kadai2/edm20627/sample_image/hoge/sample3.png new file mode 100644 index 0000000000000000000000000000000000000000..02908b23efaf7d0ee46c3703acdb1b1be8fd9b50 GIT binary patch literal 1342 zcmZ{kX;9J$7{>o;t($I}Www>I#dPd!jRlsunr0v*hMFSck@tP9CzyDm1|BJyx25HJ zn8V z)4$Kp(vmGV9@#CyURS6A6adN-<#z1%N&Fc{B-#J~f-e9-1PK7PB&UcO00;mBz?>Zb zXk-GwZ@$^J#+m@IXVgd^gV4I=Tk*Q(+qZA7?umZ5^jkXq@f7NpKF<2ONGKHbvnL)s zE=ArU2n50hNh>J zh%yLXSXh0Y^Y(QmYj}hQgX3)M;|RgoZXSu+P`^fIPjN}Z`^N5|knHX49UHq?Z@*M~ z$A|Z9qJ8|*8kxO({>sjdcx-(7ZB3hn6?uX?8~GqFij>dc%+%JkYs38Ex&f2C`K;_J zH_yj$@x`mF>;Cu*TtMc^%G%KUD>>91B+*C!|E{qPxsLtl+eh&?@{5mC9_JtNMp6jQTE zL*p>UyH1_k_;Jqk(vsj~8ygD8EibQ4Ow1-F(+djg2L`$3mLzh_3s!5N?wvsP0QXgS zGX@*^w|9!CcQV>EB005ecXu}+@QDdFf)JcFG&K2=&P3?mr_$bYzs_xK@3?y=wRa4{ z5cm@6dk5!uti^-Gq?d(7jD^KjidQC8(tteOrO$+bN?%>?%F|4h5T7dt|Ec5kl&V7?V;AxZf+q)ZZ)e~WtbkZZqW%m z?0BdSl-_bt#yd8v`aJE|1f_#M+ngFlwWeP4wuV`Hb&+-ahhwVQ1|uwK&9z}U$kl$Q zYLMV_UZ#g4ME}#p1l{OG7E)`4Q^Jrp@tHr)?CR@Vk-9=AC^9{(o^vkbD=YT}!7U3qIrge~PBHl-X=banlcZ*Et+!v)4BMVo@viTzPC zM3J1Lc04*`gL6z$zVmp5Io`=0@2uhI?<@hJ0#<=2gH@DOR54&R4KPGQ<@zPCx&|10 h@K1}H{{*~zoZMZ4{yz|opZNX&0X>8voDQ>#`WGexrZfNm literal 0 HcmV?d00001 diff --git a/kadai2/edm20627/sample_image/hoge/sample4.png b/kadai2/edm20627/sample_image/hoge/sample4.png new file mode 100644 index 0000000000000000000000000000000000000000..fc271cd818acd70231a44ce50f3df900ef8a2d0e GIT binary patch literal 2294 zcma)8S5Om(7LBs2K6gRaMp?Uy4i*SS5KxpB2uPLQq=p{Egx*^aAw*i}O-djkAcT(e z-U32Gq_%YIZT0I3zip$cs{sJ`-Uk4J!~d%fUIhR=fB?XnB>*6k z0s!#7%c$3R4gj2v(0;9_{NmL+v$v5cX$0cX>gO z@9!Vx>w;vW3*A$dsAEGcr z!&4Q6u9x!eFBRTbR&|@2BMuIj5r_g8Xo9O-f{$Ou{5(xT8Sd?yo}N*KDQZefuk7q1 z>FNcwwtWi<$qfnn+}tu;Q`ZM^h+U;^sHk}{82gGKxRQ#8vZ`n9=Q@088`M3KM4DAr z@nkYtGqWoloueEM$H^sbY59k-S;Wc;eRFfiz&MObU2pFgO--*%NhR1qkVi*Hs5rcX z6Dl|~_xt$5_V(`n!Qt}qkM16_rnY}za87Ps{m~I8DY?A2k3wBqcZZ?JDD!Ogk(JFy zeZvqC*lT2TMnl`*#x7=jVlgYHHZrO(C$}yxp|rBPCp0|o+sO2{Z_~*s6&6-erWS}V z<(+ZyrK;-QQ`1XZ+qtK&aG{1B5rK% z7@35dm_^Vxwkec(dqe>h2lSHwx9&5B}On3<%1O ziN*Hye@{p%>*=M$qHxf6iEi#mKYubNCaG9lOO1ou%*pbevQ}47`aOi8V{<~z!oeEK zXO~X%T{|treM<-r0Q?FCE6MA5PteC%rdRa&TDGb>67OHR*sA^zBw&DxD!NnpAMjlx zM++{!OK*M~)Yc(MY(^Lxhd4qYCQj%i1H|}|^}b(_)~0L&fskw*aAs;NcZGFG3mD3f z-UNuli2VL?C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KplQsx!MYX zobiSgck8*|?IO_dp6v$#x-A)`xHeXeY?Typ7UP|q{dih)2YvM#n7_V7yshOCY&aX@ z$uy_0)*EguPx?rR&pum22v!c*Zfz3W@3@6^EJ{f;3%(X)?NgNB*r6S-Qgm^ncF#mY zBXLjSo@N;MS4UqSp0M9w9F4g?Y@=eelNdU2p`t&)wl~+Vu~l+KS-CS_Tuh2sPAlrv zjWeYT*e^z4{f{;|DbfvXf4)4!ERXjvRLdUYSg~mdmQb8-E?@NgO{c)*?14(Qnh(L` zVwntes5$YE8A6R*Mup01QPc0=TFAk4^xCzO zPPJ&7ZQuZ5)QcV#qtmWYT0lpoxCLkBL?<5Xp5$a_W0DAq-J}5tD~2 zEj#rgW|}O!DHJJL-rg=`5aB!AOc+Yn2`oR-d_BWvS~x@hF~)uJGqg1x-x7y%lGAu? zS9J9Q*?=C~U|2NWQJVxDm-u<$R3THNLIw#AZTlRjm|8eSwrf88g|VuThe@L}RoU=~-0o zvRHU7n_|SN)>H)yRJSX2FRxxGKgU95_{vf<{Wgtqq)knUzAlu=?5^1M8ffu4kTg^X$$HQJ|c8|M*Ra zbNol`;{xzjT!bQSZR3JpBwONq&Ai`^-Bo%74e@$9qMF=t89k=cg;-;%bAeDB$I-7^ pTN!l9>I(ei(Pzmaef}2}hf*7CF<#~tHKl*$bnw3i4HNF?zXMfLj*9>Q literal 0 HcmV?d00001 diff --git a/kadai2/edm20627/sample_image/sample2.jpg b/kadai2/edm20627/sample_image/sample2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..839329053ebba54444d49e370f4f7c4c952871d8 GIT binary patch literal 5682 zcmeHLcQhQ%w_g^E2oVv%B6>tf1kpvJN6SX^mSiK!VzE|RLP$iET_voN5Z$WLyAWk{ zR*&9AS)I-D#ZTV*y>s4q|GmH8`^?Opa_{}zd*+-uXJ*dF&*uPFo@i)m04OLZ09qFX za6So81yE8@{H^~6kQ(?GG*nbTY7h+w^taK{U819nrzG6Un^ z@n4d^?ti^5Dg!Nu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zcXmx< zXU5O#dQl8gV@kik{$99>=WLE#ykIc&8pP0ersRaxFtflf`eOnv??%hS09Z*oX&bV~ zwm08=cO|=*gp76yw!k4aji+DK%;e(iGDAe`S@d+K`^Y1>^GCj^?>5TxhvhQsF<~n&QvkLEB%UyL*2z+X+XJu}xCgd3A zAd((jH(r0-7r-+gn%e2lz*Ky=cN+L~ae|PUAXMJ$0#G${50m%FRCKlBw_zZ#MK9Jw zm!(z zk3CftXJ53AW|6>EF4{;I-@&UHJl7$wA06HCu<~$}_Cy!SNhEvP>gb5Q){NIyrGi+j ze9e3-l#oEe^e~eP_7_wKL__Y@PI6}ssT@bZ<;t2t{hEhAMMaulVyeBl29Cwysreg= zDT6gVh12=Snyv$=xO1A@#Yd2kfE)Yl%-D0a2u&mRpXI&qe;^%fmJ>Lpeef7|8}I^C z{YUBhai3Re&hJ(9T&CCwEb_sU3>L>;$PfZ^-Xkmg7I;V!fhvDyJe_LeWa4o#qONVM zGPAC*FVs(VSYeK|pJ8&192g~-c6jW!ZsTcD{GX!R&jH&s8sPa3aiU;0uZe5*FFPf& p*<$t^K0cWSHB^63hC`(K3pMpo Date: Fri, 9 Apr 2021 01:35:54 +0900 Subject: [PATCH 15/24] =?UTF-8?q?go=20module=E3=83=91=E3=82=B9=E5=A4=89?= =?UTF-8?q?=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/edm20627/go.mod | 2 +- kadai2/edm20627/go.sum | 1 + kadai2/edm20627/main.go | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 kadai2/edm20627/go.sum diff --git a/kadai2/edm20627/go.mod b/kadai2/edm20627/go.mod index 02e3b462..91235c33 100644 --- a/kadai2/edm20627/go.mod +++ b/kadai2/edm20627/go.mod @@ -1,3 +1,3 @@ -module github.com/edm20627/gopherdojo-studyroom/kadai1/edm20627 +module github.com/edm20627/gopherdojo-studyroom/kadai2/edm20627 go 1.15 diff --git a/kadai2/edm20627/go.sum b/kadai2/edm20627/go.sum new file mode 100644 index 00000000..25c5d358 --- /dev/null +++ b/kadai2/edm20627/go.sum @@ -0,0 +1 @@ +github.com/edm20627/gopherdojo-studyroom v0.0.0-20200808023015-dd3cfe05cf7a h1:qrHQJOIqb8bC1Ulkv5H6eGp3DZgRA93eLUJr6XK/Gjk= diff --git a/kadai2/edm20627/main.go b/kadai2/edm20627/main.go index 407d2409..1bdb38bb 100644 --- a/kadai2/edm20627/main.go +++ b/kadai2/edm20627/main.go @@ -6,7 +6,7 @@ import ( "os" "strings" - "github.com/edm20627/gopherdojo-studyroom/kadai1/edm20627/imageconvert" + "github.com/edm20627/gopherdojo-studyroom/kadai2/edm20627/imageconvert" ) var ci = imageconvert.ConvertImage{} From e1ba6c2c744c68bb6cb40b08e9a4cad5ca9cd19c Mon Sep 17 00:00:00 2001 From: edm20627 Date: Fri, 9 Apr 2021 01:37:27 +0900 Subject: [PATCH 16/24] =?UTF-8?q?=E3=83=AA=E3=83=95=E3=82=A1=E3=82=AF?= =?UTF-8?q?=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/edm20627/imageconvert/imageconvert.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kadai2/edm20627/imageconvert/imageconvert.go b/kadai2/edm20627/imageconvert/imageconvert.go index f8817128..9cae9b8d 100644 --- a/kadai2/edm20627/imageconvert/imageconvert.go +++ b/kadai2/edm20627/imageconvert/imageconvert.go @@ -14,13 +14,17 @@ import ( var SupportedFormat = []string{"png", "jpg", "jpeg", "gif"} type ConvertImage struct { - filepaths []string + Filepaths []string From, To string DeleteOption bool } // Get the target files for image conversion. func (ci *ConvertImage) Get(dirs []string) error { + if len(dirs) == 0 { + return errors.New("Need to specify directory or file") + } + for _, dir := range dirs { err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { @@ -30,7 +34,7 @@ func (ci *ConvertImage) Get(dirs []string) error { if info.IsDir() || filepath.Ext(path)[1:] != ci.From { return nil } - ci.filepaths = append(ci.filepaths, path) + ci.Filepaths = append(ci.Filepaths, path) return nil }) if err != nil { @@ -42,7 +46,7 @@ func (ci *ConvertImage) Get(dirs []string) error { // Perform image conversion. func (ci *ConvertImage) Convert() error { - for _, path := range ci.filepaths { + for _, path := range ci.Filepaths { err := convert(path, ci.To, ci.DeleteOption) if err != nil { return err From 7caa18ba6e7e00f2c689b0e70c1b7fb341d885d1 Mon Sep 17 00:00:00 2001 From: edm20627 Date: Sat, 17 Apr 2021 22:45:08 +0900 Subject: [PATCH 17/24] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/edm20627/imageconvert/imageconvert.go | 9 +- .../imageconvert/imageconvert_test.go | 167 ++++++++++++++++++ 2 files changed, 174 insertions(+), 2 deletions(-) create mode 100644 kadai2/edm20627/imageconvert/imageconvert_test.go diff --git a/kadai2/edm20627/imageconvert/imageconvert.go b/kadai2/edm20627/imageconvert/imageconvert.go index 9cae9b8d..dc182741 100644 --- a/kadai2/edm20627/imageconvert/imageconvert.go +++ b/kadai2/edm20627/imageconvert/imageconvert.go @@ -13,6 +13,11 @@ import ( // Supported extensions. var SupportedFormat = []string{"png", "jpg", "jpeg", "gif"} +var ( + ErrNotSpecified = errors.New("Need to specify directory or file") + ErrMotDirectory = errors.New("Specify directory or file is not directory") +) + type ConvertImage struct { Filepaths []string From, To string @@ -22,14 +27,14 @@ type ConvertImage struct { // Get the target files for image conversion. func (ci *ConvertImage) Get(dirs []string) error { if len(dirs) == 0 { - return errors.New("Need to specify directory or file") + return ErrNotSpecified } for _, dir := range dirs { err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { if info == nil { - return errors.New(path + " is not directory") + return ErrMotDirectory } if info.IsDir() || filepath.Ext(path)[1:] != ci.From { return nil diff --git a/kadai2/edm20627/imageconvert/imageconvert_test.go b/kadai2/edm20627/imageconvert/imageconvert_test.go new file mode 100644 index 00000000..f2f95389 --- /dev/null +++ b/kadai2/edm20627/imageconvert/imageconvert_test.go @@ -0,0 +1,167 @@ +package imageconvert_test + +import ( + "image" + "image/color" + "image/gif" + "image/jpeg" + "image/png" + "os" + "reflect" + "testing" + + "github.com/edm20627/gopherdojo-studyroom/kadai2/edm20627/imageconvert" +) + +func TestGet(t *testing.T) { + success_cases := []struct { + name string + dirs []string + filepaths []string + from string + expected []string + }{ + {name: "get jpg", dirs: []string{"../testdata"}, from: "jpg", expected: []string{"../testdata/hoge/img_2.jpg", "../testdata/img_1.jpg"}}, + {name: "get png", dirs: []string{"../testdata"}, from: "png", expected: []string{"../testdata/hoge/img_2.png", "../testdata/img_1.png"}}, + {name: "get gif", dirs: []string{"../testdata"}, from: "gif", expected: []string{"../testdata/hoge/img_2.gif", "../testdata/img_1.gif"}}, + } + + for _, c := range success_cases { + for _, path := range c.expected { + testCreateImage(t, path, c.from) + defer testRemoveTestdata(t) + } + } + + for _, c := range success_cases { + t.Run(c.name, func(t *testing.T) { + ci := imageconvert.ConvertImage{From: c.from} + if err := ci.Get(c.dirs); err != nil { + t.Error(err) + } + if !reflect.DeepEqual(ci.Filepaths, c.expected) { + t.Errorf("want %v, got %v", c.expected, ci.Filepaths) + } + }) + } + + failure_cases := []struct { + name string + dirs []string + filepaths []string + from string + expected error + }{ + {name: "occurred ErrNotSpecified", dirs: []string{}, from: "jpg", expected: imageconvert.ErrNotSpecified}, + {name: "occurred ErrMotDirectory", dirs: []string{"../non_testdata"}, from: "jpg", expected: imageconvert.ErrMotDirectory}, + } + + for _, c := range failure_cases { + t.Run(c.name, func(t *testing.T) { + ci := imageconvert.ConvertImage{From: c.from} + if err := ci.Get(c.dirs); err != c.expected { + t.Errorf("want %v, got %v", c.expected, err) + } + }) + } +} + +func TestConvert(t *testing.T) { + cases := []struct { + name string + filepaths []string + from string + to string + }{ + {name: "jpg to png", filepaths: []string{"../testdata/img_1.jpg"}, from: "jpg", to: "png"}, + {name: "png to gif", filepaths: []string{"../testdata/img_1.png"}, from: "png", to: "gif"}, + {name: "gif to jpg", filepaths: []string{"../testdata/img_1.gif"}, from: "gif", to: "jpg"}, + } + + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + for _, path := range c.filepaths { + testCreateImage(t, path, c.from) + defer testRemoveTestdata(t) + } + ci := imageconvert.ConvertImage{Filepaths: c.filepaths, To: c.to} + if actual := ci.Convert(); actual != nil { + t.Error(actual) + } + }) + } +} + +func TestValid(t *testing.T) { + cases := []struct { + name string + from string + to string + expected bool + }{ + {name: "jpg to png", from: "jpg", to: "png", expected: true}, + {name: "png to jpg", from: "png", to: "jpg", expected: true}, + {name: "jpeg to gif", from: "jpeg", to: "gif", expected: true}, + {name: "gif to jpeg", from: "gif", to: "jpeg", expected: true}, + {name: "hoge to fuga", from: "hoge", to: "fuga", expected: false}, + } + + for _, c := range cases { + t.Run(c.name, func(t *testing.T) { + ci := imageconvert.ConvertImage{From: c.from, To: c.to} + if actual := ci.Valid(); c.expected != actual { + t.Errorf("want %v, got %v", c.expected, actual) + } + }) + } +} + +func testCreateImage(t *testing.T, path string, fmt string) error { + t.Helper() + + err := os.MkdirAll("../testdata/hoge", 0777) + if err != nil { + t.Error(err) + } + + file, err := os.Create(path) + if err != nil { + t.Error(err) + } + defer file.Close() + + img := image.NewRGBA(image.Rect(0, 0, 100, 100)) + for i := img.Rect.Min.Y; i < img.Rect.Max.Y; i++ { + for j := img.Rect.Min.X; j < img.Rect.Max.X; j++ { + img.Set(j, i, color.RGBA{255, 255, 0, 0}) + } + } + + switch fmt { + case "png": + if err := png.Encode(file, img); err != nil { + return err + } + case "jpg", "jpeg": + if err := jpeg.Encode(file, img, nil); err != nil { + return err + } + case "gif": + if err := gif.Encode(file, img, nil); err != nil { + return err + } + } + + return nil +} + +func testRemoveTestdata(t *testing.T) error { + t.Helper() + + err := os.RemoveAll("../testdata") + if err != nil { + t.Error(err) + } + + return nil +} From c75f90f6890e9945d258807d1b07aa911020d6cd Mon Sep 17 00:00:00 2001 From: edm20627 Date: Mon, 3 May 2021 00:35:08 +0900 Subject: [PATCH 18/24] =?UTF-8?q?fix=20=E3=82=A8=E3=83=A9=E3=83=BC?= =?UTF-8?q?=E3=83=8F=E3=83=B3=E3=83=89=E3=83=AA=E3=83=B3=E3=82=B0=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/edm20627/imageconvert/imageconvert_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/kadai2/edm20627/imageconvert/imageconvert_test.go b/kadai2/edm20627/imageconvert/imageconvert_test.go index f2f95389..b36dbd2c 100644 --- a/kadai2/edm20627/imageconvert/imageconvert_test.go +++ b/kadai2/edm20627/imageconvert/imageconvert_test.go @@ -28,7 +28,10 @@ func TestGet(t *testing.T) { for _, c := range success_cases { for _, path := range c.expected { - testCreateImage(t, path, c.from) + err := testCreateImage(t, path, c.from) + if err != nil { + t.Fatal("Failed to create the test image") + } defer testRemoveTestdata(t) } } @@ -81,7 +84,10 @@ func TestConvert(t *testing.T) { for _, c := range cases { t.Run(c.name, func(t *testing.T) { for _, path := range c.filepaths { - testCreateImage(t, path, c.from) + err := testCreateImage(t, path, c.from) + if err != nil { + t.Fatal("Failed to create the test image") + } defer testRemoveTestdata(t) } ci := imageconvert.ConvertImage{Filepaths: c.filepaths, To: c.to} From 6d344e910ddea6ec2f2dae58969bec5d532cee43 Mon Sep 17 00:00:00 2001 From: edm20627 Date: Mon, 3 May 2021 00:41:39 +0900 Subject: [PATCH 19/24] =?UTF-8?q?fix=20=E3=82=BF=E3=82=A4=E3=83=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/edm20627/imageconvert/imageconvert.go | 4 ++-- kadai2/edm20627/imageconvert/imageconvert_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/kadai2/edm20627/imageconvert/imageconvert.go b/kadai2/edm20627/imageconvert/imageconvert.go index dc182741..a8ab7c3b 100644 --- a/kadai2/edm20627/imageconvert/imageconvert.go +++ b/kadai2/edm20627/imageconvert/imageconvert.go @@ -15,7 +15,7 @@ var SupportedFormat = []string{"png", "jpg", "jpeg", "gif"} var ( ErrNotSpecified = errors.New("Need to specify directory or file") - ErrMotDirectory = errors.New("Specify directory or file is not directory") + ErrNotDirectory = errors.New("Specify directory or file is not directory") ) type ConvertImage struct { @@ -34,7 +34,7 @@ func (ci *ConvertImage) Get(dirs []string) error { err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { if info == nil { - return ErrMotDirectory + return ErrNotDirectory } if info.IsDir() || filepath.Ext(path)[1:] != ci.From { return nil diff --git a/kadai2/edm20627/imageconvert/imageconvert_test.go b/kadai2/edm20627/imageconvert/imageconvert_test.go index b36dbd2c..02bea00b 100644 --- a/kadai2/edm20627/imageconvert/imageconvert_test.go +++ b/kadai2/edm20627/imageconvert/imageconvert_test.go @@ -56,7 +56,7 @@ func TestGet(t *testing.T) { expected error }{ {name: "occurred ErrNotSpecified", dirs: []string{}, from: "jpg", expected: imageconvert.ErrNotSpecified}, - {name: "occurred ErrMotDirectory", dirs: []string{"../non_testdata"}, from: "jpg", expected: imageconvert.ErrMotDirectory}, + {name: "occurred ErrNotDirectory", dirs: []string{"../non_testdata"}, from: "jpg", expected: imageconvert.ErrNotDirectory}, } for _, c := range failure_cases { From 3f72fd8aa8297462b9e604dd560a666c75f2f132 Mon Sep 17 00:00:00 2001 From: edm20627 Date: Mon, 3 May 2021 00:44:30 +0900 Subject: [PATCH 20/24] =?UTF-8?q?fix=20=E3=83=8D=E3=82=B9=E3=83=88?= =?UTF-8?q?=E3=81=8C=E6=B7=B1=E3=81=84=E3=81=9F=E3=82=81Valid=E3=83=A1?= =?UTF-8?q?=E3=82=BD=E3=83=83=E3=83=89=E3=82=92=E3=83=AA=E3=83=95=E3=82=A1?= =?UTF-8?q?=E3=82=AF=E3=82=BF=E3=83=AA=E3=83=B3=E3=82=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/edm20627/imageconvert/imageconvert.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kadai2/edm20627/imageconvert/imageconvert.go b/kadai2/edm20627/imageconvert/imageconvert.go index a8ab7c3b..775ccee3 100644 --- a/kadai2/edm20627/imageconvert/imageconvert.go +++ b/kadai2/edm20627/imageconvert/imageconvert.go @@ -62,16 +62,16 @@ func (ci *ConvertImage) Convert() error { // Check for supported extensions. func (ci *ConvertImage) Valid() bool { + var fromSupported, toSupported bool for _, v := range SupportedFormat { if v == ci.From { - for _, v := range SupportedFormat { - if v == ci.To { - return true - } - } + fromSupported = true + } + if v == ci.To { + toSupported = true } } - return false + return fromSupported && toSupported } func convert(path string, to string, deleteOption bool) error { From 38cf9338a3bbaa3b5c646a917f12d7d22392fb88 Mon Sep 17 00:00:00 2001 From: edm20627 Date: Mon, 3 May 2021 00:50:11 +0900 Subject: [PATCH 21/24] =?UTF-8?q?fix=20TestValid=E3=81=AB=E6=AD=A3=20to=20?= =?UTF-8?q?=E5=90=A6=E3=80=81=E5=90=A6=20to=20=E6=AD=A3=E3=82=B1=E3=83=BC?= =?UTF-8?q?=E3=82=B9=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/edm20627/imageconvert/imageconvert_test.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/kadai2/edm20627/imageconvert/imageconvert_test.go b/kadai2/edm20627/imageconvert/imageconvert_test.go index 02bea00b..1418c7f1 100644 --- a/kadai2/edm20627/imageconvert/imageconvert_test.go +++ b/kadai2/edm20627/imageconvert/imageconvert_test.go @@ -105,11 +105,13 @@ func TestValid(t *testing.T) { to string expected bool }{ - {name: "jpg to png", from: "jpg", to: "png", expected: true}, - {name: "png to jpg", from: "png", to: "jpg", expected: true}, - {name: "jpeg to gif", from: "jpeg", to: "gif", expected: true}, - {name: "gif to jpeg", from: "gif", to: "jpeg", expected: true}, - {name: "hoge to fuga", from: "hoge", to: "fuga", expected: false}, + {name: "jpg to png (true to true)", from: "jpg", to: "png", expected: true}, + {name: "png to jpg (true to true)", from: "png", to: "jpg", expected: true}, + {name: "jpeg to gif (true to true)", from: "jpeg", to: "gif", expected: true}, + {name: "gif to jpeg (true to true)", from: "gif", to: "jpeg", expected: true}, + {name: "jpg to fuga (true to false)", from: "jpg", to: "fuga", expected: false}, + {name: "hoge to jpg (false to true)", from: "hoge", to: "jpg", expected: false}, + {name: "hoge to fuga (false to false)", from: "hoge", to: "fuga", expected: false}, } for _, c := range cases { From 539b81a21b40279fbc92c5af4bc052a0928d1a77 Mon Sep 17 00:00:00 2001 From: edm20627 Date: Mon, 3 May 2021 03:19:28 +0900 Subject: [PATCH 22/24] =?UTF-8?q?fix=20=E3=83=86=E3=82=B9=E3=83=88?= =?UTF-8?q?=E7=94=A8=E7=94=BB=E5=83=8F=E3=82=92=E4=BD=BF=E7=94=A8=E3=81=97?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=ABtastdata=E3=82=92=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../imageconvert/imageconvert_test.go | 83 ++---------------- kadai2/edm20627/testdata/hoge/img_1.jpg | Bin 0 -> 791 bytes kadai2/edm20627/testdata/hoge/img_2.png | Bin 0 -> 298 bytes kadai2/edm20627/testdata/hoge/img_3.gif | Bin 0 -> 955 bytes kadai2/edm20627/testdata/img_1.jpg | Bin 0 -> 907 bytes kadai2/edm20627/testdata/img_2.png | Bin 0 -> 1795 bytes kadai2/edm20627/testdata/img_3.gif | Bin 0 -> 1546 bytes 7 files changed, 5 insertions(+), 78 deletions(-) create mode 100644 kadai2/edm20627/testdata/hoge/img_1.jpg create mode 100644 kadai2/edm20627/testdata/hoge/img_2.png create mode 100644 kadai2/edm20627/testdata/hoge/img_3.gif create mode 100644 kadai2/edm20627/testdata/img_1.jpg create mode 100644 kadai2/edm20627/testdata/img_2.png create mode 100644 kadai2/edm20627/testdata/img_3.gif diff --git a/kadai2/edm20627/imageconvert/imageconvert_test.go b/kadai2/edm20627/imageconvert/imageconvert_test.go index 1418c7f1..7929a90c 100644 --- a/kadai2/edm20627/imageconvert/imageconvert_test.go +++ b/kadai2/edm20627/imageconvert/imageconvert_test.go @@ -1,12 +1,6 @@ package imageconvert_test import ( - "image" - "image/color" - "image/gif" - "image/jpeg" - "image/png" - "os" "reflect" "testing" @@ -21,19 +15,9 @@ func TestGet(t *testing.T) { from string expected []string }{ - {name: "get jpg", dirs: []string{"../testdata"}, from: "jpg", expected: []string{"../testdata/hoge/img_2.jpg", "../testdata/img_1.jpg"}}, - {name: "get png", dirs: []string{"../testdata"}, from: "png", expected: []string{"../testdata/hoge/img_2.png", "../testdata/img_1.png"}}, - {name: "get gif", dirs: []string{"../testdata"}, from: "gif", expected: []string{"../testdata/hoge/img_2.gif", "../testdata/img_1.gif"}}, - } - - for _, c := range success_cases { - for _, path := range c.expected { - err := testCreateImage(t, path, c.from) - if err != nil { - t.Fatal("Failed to create the test image") - } - defer testRemoveTestdata(t) - } + {name: "get jpg", dirs: []string{"../testdata"}, from: "jpg", expected: []string{"../testdata/hoge/img_1.jpg", "../testdata/img_1.jpg"}}, + {name: "get png", dirs: []string{"../testdata"}, from: "png", expected: []string{"../testdata/hoge/img_2.png", "../testdata/img_2.png"}}, + {name: "get gif", dirs: []string{"../testdata"}, from: "gif", expected: []string{"../testdata/hoge/img_3.gif", "../testdata/img_3.gif"}}, } for _, c := range success_cases { @@ -77,19 +61,12 @@ func TestConvert(t *testing.T) { to string }{ {name: "jpg to png", filepaths: []string{"../testdata/img_1.jpg"}, from: "jpg", to: "png"}, - {name: "png to gif", filepaths: []string{"../testdata/img_1.png"}, from: "png", to: "gif"}, - {name: "gif to jpg", filepaths: []string{"../testdata/img_1.gif"}, from: "gif", to: "jpg"}, + {name: "png to gif", filepaths: []string{"../testdata/img_2.png"}, from: "png", to: "gif"}, + {name: "gif to jpg", filepaths: []string{"../testdata/img_3.gif"}, from: "gif", to: "jpg"}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { - for _, path := range c.filepaths { - err := testCreateImage(t, path, c.from) - if err != nil { - t.Fatal("Failed to create the test image") - } - defer testRemoveTestdata(t) - } ci := imageconvert.ConvertImage{Filepaths: c.filepaths, To: c.to} if actual := ci.Convert(); actual != nil { t.Error(actual) @@ -123,53 +100,3 @@ func TestValid(t *testing.T) { }) } } - -func testCreateImage(t *testing.T, path string, fmt string) error { - t.Helper() - - err := os.MkdirAll("../testdata/hoge", 0777) - if err != nil { - t.Error(err) - } - - file, err := os.Create(path) - if err != nil { - t.Error(err) - } - defer file.Close() - - img := image.NewRGBA(image.Rect(0, 0, 100, 100)) - for i := img.Rect.Min.Y; i < img.Rect.Max.Y; i++ { - for j := img.Rect.Min.X; j < img.Rect.Max.X; j++ { - img.Set(j, i, color.RGBA{255, 255, 0, 0}) - } - } - - switch fmt { - case "png": - if err := png.Encode(file, img); err != nil { - return err - } - case "jpg", "jpeg": - if err := jpeg.Encode(file, img, nil); err != nil { - return err - } - case "gif": - if err := gif.Encode(file, img, nil); err != nil { - return err - } - } - - return nil -} - -func testRemoveTestdata(t *testing.T) error { - t.Helper() - - err := os.RemoveAll("../testdata") - if err != nil { - t.Error(err) - } - - return nil -} diff --git a/kadai2/edm20627/testdata/hoge/img_1.jpg b/kadai2/edm20627/testdata/hoge/img_1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..15a202691fbbea052cef7c9fd3d00d016cdd8cd1 GIT binary patch literal 791 zcmex=KU|?coW@chxW@Tkz0jjJ8$}zAA zvI;30I#U-U>$dGXcJ4ZK_{h;?$4{I*b?NeztJkjIxOwa0qsLF4K70P+<*SdM zK7aZ8?fZ|PzZe;qA>IL!5Dy{wM-b>ACKeWE7Iu(-7@5j}m|2j8Rnd@5$T5&Tu~1ma zsF6d&Y2w0-2RW6EgFc8R6KQ!#m{`Vr(Mu#brIP!m}`f_n(=pZ~WQc$gW15ymXY ZV9)SPOJmV~K3juDT^bBS7&HIB2>_zd1Bn0t literal 0 HcmV?d00001 diff --git a/kadai2/edm20627/testdata/hoge/img_2.png b/kadai2/edm20627/testdata/hoge/img_2.png new file mode 100644 index 0000000000000000000000000000000000000000..6622c9821123a807a2e80ae0cd04d38be52b9189 GIT binary patch literal 298 zcmeAS@N?(olHy`uVBq!ia0vp^DImLeO z^~dZMFx4;N=oA!ER&n#_nINHP=#Pf)FASgaoVLMp=Aj2{M?M_>jQMf=$3e7E3{K1qs3` zxFAc41Z0q4p&+bR;LMv#E!tnwZ!7F$T@B91vfdnW4FFi@nETOzC$|lMZ+VeuWR7r6n zTq+F$BM#WpG)N7ta1od^F!WIAg`!G|qj05Ey`G1mrGt9TF%L6KE1~5s3$2Zu6TOJ3 zGJ>PSF9yd^iWCn)y>m{_r3B5$iILCvw!z>bdN2)8@hF{v#+(a^!`j* z>lv9FTmCS7@9?SVy{+Ys=k6aJp6PC^?1c}GtA*C~O8fkylT(Xxjnz*V9uHo3d)up@ zquHU`9X;b~Uq&ok!`wtzvy!CtX&E3uuaqqwpoc;%sbG*R- literal 0 HcmV?d00001 diff --git a/kadai2/edm20627/testdata/img_1.jpg b/kadai2/edm20627/testdata/img_1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4f49baba7ba2ef7d4bd40827eb25e408dcfd3d03 GIT binary patch literal 907 zcmex=KU|?coW@chxW@Tkz0jjJ8$}zAA zvI;30I#U-U>$dGXcJ4ZK_{h;?$4{I*b?NeztJkjIxOwa0qsLF4K70P+<*SdM zK7aZ8?fZ|PzZe;qA>IL!5Dy{wM-b>ACKeWE7Iu(-7@5j}m|2j8Rnd@5$T5&Tu~1ma zsF6d&Y2w0-2RW6EgFc8R6KQ!#m{`Vr(Mu#brIP!m}`f_n(=pZ~WQc$gW15ymXY zV9)SPOJm9L>z~&jepBUi(N!cO(N+DaXX6XQ&=ZPRf(mC@KbN_9;?SduuJXOw41u1W z{fYh)8(wKFT9D`}5~|3Sv8b!AK_t+X0g8E;y1eYQ${2y-XA&<>n(}4Iud7Eu<}w5V zanhu&DA{Wd7uT6O=k7%rEvjh4#=#9Knp~fnLWKSkyO}E6$x};Mc@E~ zMO_*UK+L%0LCHJKE5}~c-;=*IKg##@_c|v>&-pX@9e8z3>etvi{>@^u>e5)kRH6{X jJh%Ny(EL4HuKwQmS9_Ia_5O$TzYCRLEb4ly@&6_O8q`3G literal 0 HcmV?d00001 diff --git a/kadai2/edm20627/testdata/img_2.png b/kadai2/edm20627/testdata/img_2.png new file mode 100644 index 0000000000000000000000000000000000000000..7a38caec5ca6f1f37240abad38704df2852c4333 GIT binary patch literal 1795 zcmV+e2mJVnP)!V=(lvS6?)*g5ZG2{Ta$cb){SWQVFT1p4Z2ujfasQp&B|)8OCVyBe zN(E?TJ(0)A9pn3d&6}P+8z>eqp}A-Sjsqy}$peZ7Oh^=~>x`dx;}~VV`Kjso*Y-a$ zJ^zOB{l8{>|1*JN0TZeaV_84(ZEHn0M)gLL0ma)hG0El0<5h4h73v$uY-vtqX%3$F zUu`d9`;M2pnqHxZ_o7JbFgI44ugqmwQHwTg?+>pk6<77(5z*Vd48=l>1x%>It5Bu5 z&N=1NBzx{Hy-^yT{B3!5**m4OUl%GQQC2VGC=?5r&@7=>W&FJB&d=NE~a+GP5kZ)C%WI<@Dgf?0KM|hkATD%E4!Po5k&M zu2H;k%FlbxYkyK4*`@!J;rWSp`Ef?CEw}YCJx7SKfC**13J=e~oE^`#5Ar(Pae>

Wf)KPL^V1YoffC*(NRx7Ngk~cp+P%Q222J(v84fR8}CO{8=M;S9m_#@buE=OPxIAie-JNL9f}cK9)7SLQk?{Xebsip>|V~^%PQ+oLrH0d~~W z@TI}#k#*(i2hZm zbretz6>zMf9u#Dx85;7cwfInJf|w~NzcrlKA6VEPTs=LWYVEg;3dUQ}JC-$59I>r+ z&^i&lV|g#Py{bZ=_SGr3m(FK?vF8t}xCASXXlwuaIJgXtr>j|7sXHb;O1?{vlFyCz zHTJ|o^p0iCl+HnTJot=&kE-BU_QAVfUm7bDhYGZMFowt*`v*VRmiyU?mFB(b@dB-Y zW7!AqKo9$ea{E-&@A%l~OX=*_=k470-mv~z-h8a+6{~K;_Vxa2D;93PzA>-QbQ}G&kDyPqO0_((jrg^$5PQ4p!~R8Ul$$_6bo2UJH>(ml|v03 z3&DFCM89957C1^dAjSeFz_EY{a4cW~91EBL#{wq6v49D1EMNkQ$QS%z(Pqp~|6lo^ zTpVT7yXP+aHp;Cpz5d5*A~f80InBTkIp;4u^ZDr4jb|TzGCo!JVBbL58|_@rEBt2n zxzTaI9_$aj)ELjx;#O~S_{&{B-`h;DD>tb#+`)d?xj`xL^empfIsIo^0`FM0sx*xpwZkm;J?#$x{H+Utnu(#9ys(&GApZtyAq2*Eg zy&qrtYt;Vi*T27zwkM*Sa&PjwP^^kGc*wpye1tlQyG%@Ye3U$VlLKDU+vi<3`XQak z8!^5GW39?-`4qw2c3#b1OUU7holPFsXXlpR8C`{b;VmNS$nxN>2R57 zELz#SRp1|bBo0PMvpgZ)t%I4iM|WuYy-GD~;BYH>ZK8LqSV&xb^n6Qz^>vF6x~CQv lAEF<&&)K*CzW@LL|NoYZq*3k;Bx?Ww002ovPDHLkV1k2ua3BBx literal 0 HcmV?d00001 diff --git a/kadai2/edm20627/testdata/img_3.gif b/kadai2/edm20627/testdata/img_3.gif new file mode 100644 index 0000000000000000000000000000000000000000..4ad9940d203fe26b41668ff8b74072fc73e91b0f GIT binary patch literal 1546 zcmX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az@=TM551o`X11^)qT|I-Hm literal 0 HcmV?d00001 From 113322206c0cdf621e689eb9bdaf4e59bfad05cb Mon Sep 17 00:00:00 2001 From: edm20627 Date: Mon, 3 May 2021 03:24:38 +0900 Subject: [PATCH 23/24] =?UTF-8?q?fix=20DeleteOption=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/edm20627/imageconvert/imageconvert.go | 4 +- .../imageconvert/imageconvert_test.go | 38 +++++++++++++++---- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/kadai2/edm20627/imageconvert/imageconvert.go b/kadai2/edm20627/imageconvert/imageconvert.go index 775ccee3..eede47e8 100644 --- a/kadai2/edm20627/imageconvert/imageconvert.go +++ b/kadai2/edm20627/imageconvert/imageconvert.go @@ -18,6 +18,8 @@ var ( ErrNotDirectory = errors.New("Specify directory or file is not directory") ) +var OsRemove = os.Remove + type ConvertImage struct { Filepaths []string From, To string @@ -108,7 +110,7 @@ func convert(path string, to string, deleteOption bool) error { } if deleteOption { - if err := os.Remove(path); err != nil { + if err := OsRemove(path); err != nil { return err } } diff --git a/kadai2/edm20627/imageconvert/imageconvert_test.go b/kadai2/edm20627/imageconvert/imageconvert_test.go index 7929a90c..572b6e71 100644 --- a/kadai2/edm20627/imageconvert/imageconvert_test.go +++ b/kadai2/edm20627/imageconvert/imageconvert_test.go @@ -1,7 +1,10 @@ package imageconvert_test import ( + "errors" + "os" "reflect" + "strings" "testing" "github.com/edm20627/gopherdojo-studyroom/kadai2/edm20627/imageconvert" @@ -55,22 +58,41 @@ func TestGet(t *testing.T) { func TestConvert(t *testing.T) { cases := []struct { - name string - filepaths []string - from string - to string + name string + filepaths []string + from string + to string + deleteOption bool }{ - {name: "jpg to png", filepaths: []string{"../testdata/img_1.jpg"}, from: "jpg", to: "png"}, - {name: "png to gif", filepaths: []string{"../testdata/img_2.png"}, from: "png", to: "gif"}, - {name: "gif to jpg", filepaths: []string{"../testdata/img_3.gif"}, from: "gif", to: "jpg"}, + {name: "jpg to png", filepaths: []string{"../testdata/img_1.jpg"}, from: "jpg", to: "png", deleteOption: false}, + {name: "png to gif", filepaths: []string{"../testdata/img_2.png"}, from: "png", to: "gif", deleteOption: false}, + {name: "gif to jpg", filepaths: []string{"../testdata/img_3.gif"}, from: "gif", to: "jpg", deleteOption: false}, + {name: "jpg to png", filepaths: []string{"../testdata/img_1.jpg"}, from: "jpg", to: "png", deleteOption: true}, + {name: "png to gif", filepaths: []string{"../testdata/img_2.png"}, from: "png", to: "gif", deleteOption: true}, + {name: "gif to jpg", filepaths: []string{"../testdata/img_3.gif"}, from: "gif", to: "jpg", deleteOption: true}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { - ci := imageconvert.ConvertImage{Filepaths: c.filepaths, To: c.to} + imageconvert.OsRemove = func(path string) error { + for _, filepath := range c.filepaths { + if path == filepath { + return nil + } + } + return errors.New("failed to delete for conversion source image") + } + + ci := imageconvert.ConvertImage{Filepaths: c.filepaths, To: c.to, DeleteOption: c.deleteOption} if actual := ci.Convert(); actual != nil { t.Error(actual) } + for _, filepath := range c.filepaths { + targetFile := strings.Replace(filepath, c.from, c.to, 1) + if err := os.Remove(targetFile); err != nil { + t.Fatal(err) + } + } }) } } From 6d99bb204c92d4a2bbf494102a50d3adf605edc8 Mon Sep 17 00:00:00 2001 From: edm20627 Date: Thu, 6 May 2021 20:53:47 +0900 Subject: [PATCH 24/24] =?UTF-8?q?fix=20=E5=AE=9F=E9=9A=9B=E3=81=AB?= =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E3=81=A7=E3=83=95=E3=82=A1=E3=82=A4?= =?UTF-8?q?=E3=83=AB=E5=89=8A=E9=99=A4=E3=81=97=E3=81=A6=E3=81=84=E3=82=8B?= =?UTF-8?q?=E3=81=8B=E7=A2=BA=E8=AA=8D=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88?= =?UTF-8?q?=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kadai2/edm20627/imageconvert/imageconvert.go | 4 +- .../imageconvert/imageconvert_test.go | 121 +++++++++++++++--- 2 files changed, 107 insertions(+), 18 deletions(-) diff --git a/kadai2/edm20627/imageconvert/imageconvert.go b/kadai2/edm20627/imageconvert/imageconvert.go index eede47e8..775ccee3 100644 --- a/kadai2/edm20627/imageconvert/imageconvert.go +++ b/kadai2/edm20627/imageconvert/imageconvert.go @@ -18,8 +18,6 @@ var ( ErrNotDirectory = errors.New("Specify directory or file is not directory") ) -var OsRemove = os.Remove - type ConvertImage struct { Filepaths []string From, To string @@ -110,7 +108,7 @@ func convert(path string, to string, deleteOption bool) error { } if deleteOption { - if err := OsRemove(path); err != nil { + if err := os.Remove(path); err != nil { return err } } diff --git a/kadai2/edm20627/imageconvert/imageconvert_test.go b/kadai2/edm20627/imageconvert/imageconvert_test.go index 572b6e71..c7ac1d2f 100644 --- a/kadai2/edm20627/imageconvert/imageconvert_test.go +++ b/kadai2/edm20627/imageconvert/imageconvert_test.go @@ -1,8 +1,11 @@ package imageconvert_test import ( - "errors" + "fmt" + "io" + "io/ioutil" "os" + "path" "reflect" "strings" "testing" @@ -57,6 +60,12 @@ func TestGet(t *testing.T) { } func TestConvert(t *testing.T) { + // テスト実行ディレクトリを作成するためにtastdataをコピー + targetDir := "../test_execution_dir" + if err := testDirCopy(t, "../testdata", targetDir); err != nil { + t.Fatal("Failed to copy the test directory") + } + cases := []struct { name string filepaths []string @@ -64,29 +73,38 @@ func TestConvert(t *testing.T) { to string deleteOption bool }{ - {name: "jpg to png", filepaths: []string{"../testdata/img_1.jpg"}, from: "jpg", to: "png", deleteOption: false}, - {name: "png to gif", filepaths: []string{"../testdata/img_2.png"}, from: "png", to: "gif", deleteOption: false}, - {name: "gif to jpg", filepaths: []string{"../testdata/img_3.gif"}, from: "gif", to: "jpg", deleteOption: false}, - {name: "jpg to png", filepaths: []string{"../testdata/img_1.jpg"}, from: "jpg", to: "png", deleteOption: true}, - {name: "png to gif", filepaths: []string{"../testdata/img_2.png"}, from: "png", to: "gif", deleteOption: true}, - {name: "gif to jpg", filepaths: []string{"../testdata/img_3.gif"}, from: "gif", to: "jpg", deleteOption: true}, + {name: "jpg to png(deleteOption: false)", filepaths: []string{targetDir + "/img_1.jpg"}, from: "jpg", to: "png", deleteOption: false}, + {name: "png to gif(deleteOption: false)", filepaths: []string{targetDir + "/img_2.png"}, from: "png", to: "gif", deleteOption: false}, + {name: "gif to jpg(deleteOption: false)", filepaths: []string{targetDir + "/img_3.gif"}, from: "gif", to: "jpg", deleteOption: false}, + {name: "jpg to png(deleteOption: true)", filepaths: []string{targetDir + "/img_1.jpg"}, from: "jpg", to: "png", deleteOption: true}, + {name: "png to gif(deleteOption: true)", filepaths: []string{targetDir + "/img_2.png"}, from: "png", to: "gif", deleteOption: true}, + {name: "gif to jpg(deleteOption: true)", filepaths: []string{targetDir + "/img_3.gif"}, from: "gif", to: "jpg", deleteOption: true}, } for _, c := range cases { t.Run(c.name, func(t *testing.T) { - imageconvert.OsRemove = func(path string) error { - for _, filepath := range c.filepaths { - if path == filepath { - return nil - } - } - return errors.New("failed to delete for conversion source image") - } ci := imageconvert.ConvertImage{Filepaths: c.filepaths, To: c.to, DeleteOption: c.deleteOption} if actual := ci.Convert(); actual != nil { t.Error(actual) } + + // ファイルのありなしを確認 + for _, fileName := range c.filepaths { + // 変換前ファイル + _, err := os.Stat(fileName) + if (err == nil) == c.deleteOption { + t.Fatal(err) + } + + // 変換後ファイル + targetFileName := strings.Replace(fileName, c.from, c.to, 1) + _, err = os.Stat(targetFileName) + if err != nil { + t.Fatal(err) + } + } + for _, filepath := range c.filepaths { targetFile := strings.Replace(filepath, c.from, c.to, 1) if err := os.Remove(targetFile); err != nil { @@ -95,6 +113,11 @@ func TestConvert(t *testing.T) { } }) } + + // テスト実行ディレクトリを削除 + if err := os.RemoveAll(targetDir); err != nil { + fmt.Println(err) + } } func TestValid(t *testing.T) { @@ -122,3 +145,71 @@ func TestValid(t *testing.T) { }) } } + +func testDirCopy(t *testing.T, src string, dst string) error { + t.Helper() + var err error + var fds []os.FileInfo + var srcinfo os.FileInfo + + if srcinfo, err = os.Stat(src); err != nil { + t.Error(err) + } + + if err = os.MkdirAll(dst, srcinfo.Mode()); err != nil { + t.Error(err) + + } + + if fds, err = ioutil.ReadDir(src); err != nil { + t.Error(err) + + } + + for _, fd := range fds { + srcfp := path.Join(src, fd.Name()) + dstfp := path.Join(dst, fd.Name()) + + if fd.IsDir() { + if err = testDirCopy(t, srcfp, dstfp); err != nil { + t.Error(err) + + } + } else { + if err = testFileCopy(t, srcfp, dstfp); err != nil { + t.Error(err) + + } + } + } + + return nil +} + +func testFileCopy(t *testing.T, src, dst string) error { + t.Helper() + var err error + var srcfd *os.File + var dstfd *os.File + var srcinfo os.FileInfo + + if srcfd, err = os.Open(src); err != nil { + t.Error(err) + } + defer srcfd.Close() + + if dstfd, err = os.Create(dst); err != nil { + t.Error(err) + } + defer dstfd.Close() + + if _, err = io.Copy(dstfd, srcfd); err != nil { + t.Error(err) + } + + if srcinfo, err = os.Stat(src); err != nil { + t.Error(err) + } + + return os.Chmod(dst, srcinfo.Mode()) +}