Skip to content

Commit

Permalink
update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Nota30 committed Feb 11, 2024
1 parent 8107447 commit 59806fb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ func main() {
gify := gifenc.Config{}

// Decode
imgs, err := gify.Decode("gif path")
var gif *gif.GIF // Provide a gif
imgs, err := gify.Decode(gif)
if err != nil {
println(err)
}

// Encode
encoded, err := gify.Encode("folder path")
var images []image.Image // Provide an array of images
encoded, err := gify.Encode(images)
if err != nil {
println(err)
}
Expand Down
36 changes: 18 additions & 18 deletions test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,54 +15,54 @@ func main() {
encode()
}

// Encode
func encode() {
// Decode
func decode() {
init := gifenc.Config{
Delay: 30,
}

images := getImages()

encoded, err := init.Encode(images)
file, err := os.Open("test/input/sword.gif")
if err != nil {
fmt.Print(err)
}

newfile, err := os.Create(fmt.Sprintf("%s%s", "test/", "sword_test.gif"))
gif, err := gif.DecodeAll(file)
if err != nil {
fmt.Print(err)
}
defer newfile.Close()

encodeErr := gif.EncodeAll(newfile, encoded)

if encodeErr != nil {
imgs, err := init.Decode(gif)
if err != nil {
fmt.Print(err)
}

saveImages(imgs)
}

// Decode
func decode() {
// Encode
func encode() {
init := gifenc.Config{
Delay: 30,
}

file, err := os.Open("test/input/sword.gif")
images := getImages()

encoded, err := init.Encode(images)
if err != nil {
fmt.Print(err)
}

gif, err := gif.DecodeAll(file)
newfile, err := os.Create(fmt.Sprintf("%s%s", "test/", "sword_test.gif"))
if err != nil {
fmt.Print(err)
}
defer newfile.Close()

imgs, err := init.Decode(gif)
if err != nil {
encodeErr := gif.EncodeAll(newfile, encoded)

if encodeErr != nil {
fmt.Print(err)
}

saveImages(imgs)
}

func saveImages(imgs []*image.RGBA) {
Expand Down

0 comments on commit 59806fb

Please sign in to comment.