diff --git a/decode.go b/decode.go index 98fd790..1a6f6f0 100644 --- a/decode.go +++ b/decode.go @@ -56,7 +56,7 @@ func split(file io.Reader, width int, height int, output Output) (err error) { err = png.Encode(file, dst) if err != nil { - return fmt.Errorf("error while creating image: %s", err) + return fmt.Errorf("error while encoding image: %s", err) } file.Close() diff --git a/encode.go b/encode.go index f5f9a5c..560adf4 100644 --- a/encode.go +++ b/encode.go @@ -18,7 +18,6 @@ func (config Config) Encode(path string) error { var allFiles []string for _, file := range files { - fmt.Print(file.Name()) allFiles = append(allFiles, file.Name()) } @@ -47,7 +46,11 @@ func (config Config) Encode(path string) error { animated.Delay = append(animated.Delay, config.Delay) } - file, err := os.Create(config.Output.Name) + if config.Output.Name == "" { + config.Output.Name = "final" + } + + file, err := os.Create(fmt.Sprintf("%s%s%s", config.Output.Path, config.Output.Name, ".gif")) if err != nil { return fmt.Errorf("error while creating file: %s", err) } @@ -55,7 +58,7 @@ func (config Config) Encode(path string) error { encodeErr := gif.EncodeAll(file, &animated) if encodeErr != nil { - return fmt.Errorf("error while creating file: %s", err) + return fmt.Errorf("error while encoding file: %s", err) } return nil diff --git a/test/input/sword.gif b/test/input/sword.gif new file mode 100644 index 0000000..9e40553 Binary files /dev/null and b/test/input/sword.gif differ diff --git a/test/output/sword0.png b/test/output/sword0.png new file mode 100644 index 0000000..5d3c07f Binary files /dev/null and b/test/output/sword0.png differ diff --git a/test/output/sword1.png b/test/output/sword1.png new file mode 100644 index 0000000..84886d0 Binary files /dev/null and b/test/output/sword1.png differ diff --git a/test/output/sword2.png b/test/output/sword2.png new file mode 100644 index 0000000..67ef66b Binary files /dev/null and b/test/output/sword2.png differ diff --git a/test/output/sword3.png b/test/output/sword3.png new file mode 100644 index 0000000..e95193a Binary files /dev/null and b/test/output/sword3.png differ diff --git a/test/output/sword4.png b/test/output/sword4.png new file mode 100644 index 0000000..fa691b0 Binary files /dev/null and b/test/output/sword4.png differ diff --git a/test/output/sword5.png b/test/output/sword5.png new file mode 100644 index 0000000..ff6a550 Binary files /dev/null and b/test/output/sword5.png differ diff --git a/test/test.go b/test/test.go new file mode 100644 index 0000000..fe66d5e --- /dev/null +++ b/test/test.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + + "github.com/Nota30/gifenc" +) + +func main() { + init := gifenc.Config{ + Output: gifenc.Output{ + Name: "sword1", + Path: "test/output/", + }, + Delay: 20, + } + + // err := init.Decode("test/input/sword.gif") + // if err != nil { + // fmt.Print(err) + // } + + err := init.Encode("test/output/") + if err != nil { + fmt.Print(err) + } +} diff --git a/types.go b/types.go index 95094de..8df41ff 100644 --- a/types.go +++ b/types.go @@ -1,7 +1,7 @@ package gifenc type Output struct { - Name string `default:"img"` + Name string Path string }