Skip to content

Commit

Permalink
modify how decode works and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nota30 committed Feb 10, 2024
1 parent 4cd1150 commit 29fd470
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
9 changes: 6 additions & 3 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down Expand Up @@ -47,15 +46,19 @@ 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)
}
defer file.Close()

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
Expand Down
Binary file added test/input/sword.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/output/sword0.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/output/sword1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/output/sword2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/output/sword3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/output/sword4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added test/output/sword5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
27 changes: 27 additions & 0 deletions test/test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package gifenc

type Output struct {
Name string `default:"img"`
Name string
Path string
}

Expand Down

0 comments on commit 29fd470

Please sign in to comment.