diff --git a/kadai1/shuntakeuch1/data/150x150.png b/kadai1/shuntakeuch1/data/150x150.png new file mode 100644 index 0000000..32cf9f9 Binary files /dev/null and b/kadai1/shuntakeuch1/data/150x150.png differ diff --git a/kadai1/shuntakeuch1/ifconv/ifconv.go b/kadai1/shuntakeuch1/ifconv/ifconv.go new file mode 100644 index 0000000..cf62742 --- /dev/null +++ b/kadai1/shuntakeuch1/ifconv/ifconv.go @@ -0,0 +1,33 @@ +package ifconv + +import ( + "image" + "image/jpeg" + "os" +) + +func Execute(dir string, before_f string, after_f string) error { + sf, err := os.Open("test1.png") + if err != nil { + return err + } + defer sf.Close() + + img, format, err := image.Decode(sf) + if err != nil { + return err + } + + if format == "hoge" { + return err + } + + file, err := os.Create("test1.jpeg") + if err != nil { + return err + } + defer file.Close() + + jpeg.Encode(file, img, &jpeg.Options{}) + return nil +} diff --git a/kadai1/shuntakeuch1/ifconv/ifconv_test.go b/kadai1/shuntakeuch1/ifconv/ifconv_test.go new file mode 100644 index 0000000..7d96836 --- /dev/null +++ b/kadai1/shuntakeuch1/ifconv/ifconv_test.go @@ -0,0 +1,9 @@ +package ifconv + +import ( + "testing" +) + +func TestExecute(t *testing.T) { + Execute("foo", "bar", "hoge") +} diff --git a/kadai1/shuntakeuch1/main.go b/kadai1/shuntakeuch1/main.go new file mode 100644 index 0000000..0a8d6dc --- /dev/null +++ b/kadai1/shuntakeuch1/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "flag" + "fmt" + "os" + + "github.com/gopherdojo/dojo5/kadai1/shuntakeuch1/ifconv" +) + +// flagをつけてbefore format と after formatのデフォルトをきめる +var before = flag.String("b", "jpg", "変換前画像形式を指定してください") +var after = flag.String("a", "png", "変換後画像形式を指定してください") + +func main() { + flag.Parse() + dir := flag.Arg(0) + // ディレクトリを聞く or 引数にないと強制終了 + if dir == "" { + fmt.Println("ディレクトリを指定してください") + os.Exit(0) + } + + result := ifconv.Execute(dir, *before, *after) + fmt.Println(result) +} diff --git a/kadai1/shuntakeuch1/test1.png b/kadai1/shuntakeuch1/test1.png new file mode 100644 index 0000000..32cf9f9 Binary files /dev/null and b/kadai1/shuntakeuch1/test1.png differ