diff --git a/image.go b/image.go index c5e81cc..326a5da 100644 --- a/image.go +++ b/image.go @@ -34,14 +34,21 @@ func View(p string) { printImage(30, src) } -func printImage(xsize int, image image.Image) { - xmax := image.Bounds().Max.X - ratio := float64(xsize) / float64(xmax) - width := uint(float64(xmax) * ratio) - img := resize.Resize(width, 0, image, resize.Bicubic) - for i := 0; i < img.Bounds().Max.Y; i++ { - for j := 0; j < img.Bounds().Max.X; j++ { - r, g, b, _ := img.At(j, i).RGBA() +func printImage(limit int, image image.Image) { + if image.Bounds().Max.X > image.Bounds().Max.Y { + xmax := image.Bounds().Max.X + ratio := float64(limit) / float64(xmax) + width := uint(float64(xmax) * ratio) + image = resize.Resize(width, 0, image, resize.Bicubic) + } else { + ymax := image.Bounds().Max.Y + ratio := float64(limit) / float64(ymax) + height := uint(float64(ymax) * ratio) + image = resize.Resize(0, height, image, resize.Bicubic) + } + for i := 0; i < image.Bounds().Max.Y; i++ { + for j := 0; j < image.Bounds().Max.X; j++ { + r, g, b, _ := image.At(j, i).RGBA() r = ansi.To256(r) g = ansi.To256(g) b = ansi.To256(b)