Hello mates, I am trying to open a gif image on terminal calling it from inside the code. I successfully open PNGs using the For
twice, I tried add a third For
loop aiming to represent the amount of frames 0 to 9
, nevertheless this attempt did not work.
Code:
File, err := os.Open(path_image)
if err != nil {
log.Fatal(err)
}
defer File.Close()
img, err := gif.Decode(File)
if err != nil {
log.Fatal(err)
}
img = resize.Resize(70, 70, img, resize.Lanczos3)
levels := []string{" ", "░", "▒", "▓", "█"}
for i := 0; i < 9; i++ {
for y := img.Bounds().Min.Y; y < img.Bounds().Max.Y; y++ {
for x := img.Bounds().Min.X; x < img.Bounds().Max.X; x++ {
c := color.GrayModel.Convert(img.At(x, y)).(color.Gray)
level := c.Y / 51 // 51 * 5 = 255
if level == 5 {
level--
}
fmt.Print(levels[level], " ")
}
fmt.Print("\n")
}
}
How could I open the gif with its frames?