Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kadai1 shuntakeuch1 #12

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added kadai1/shuntakeuch1/data/150x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions kadai1/shuntakeuch1/ifconv/ifconv.go
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 9 additions & 0 deletions kadai1/shuntakeuch1/ifconv/ifconv_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ifconv

import (
"testing"
)

func TestExecute(t *testing.T) {
Execute("foo", "bar", "hoge")
}
26 changes: 26 additions & 0 deletions kadai1/shuntakeuch1/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
Binary file added kadai1/shuntakeuch1/test1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.