shorter and narrower

master
bel 2023-04-04 23:03:02 -06:00
parent 83769edc02
commit b24be48129
1 changed files with 15 additions and 8 deletions

View File

@ -34,14 +34,21 @@ func View(p string) {
printImage(30, src)
}
func printImage(xsize int, image image.Image) {
func printImage(limit int, image image.Image) {
if image.Bounds().Max.X > image.Bounds().Max.Y {
xmax := image.Bounds().Max.X
ratio := float64(xsize) / float64(xmax)
ratio := float64(limit) / 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()
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)