Skip to content

Commit

Permalink
use lipgloss
Browse files Browse the repository at this point in the history
  • Loading branch information
mistakenelf committed Sep 2, 2021
1 parent d1f4321 commit 82a4589
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions internal/asciimage/asciiImage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"image"
"strings"

"github.com/charmbracelet/lipgloss"
"github.com/lucasb-eyer/go-colorful"
"github.com/muesli/termenv"
"github.com/nfnt/resize"
)

Expand All @@ -23,24 +23,22 @@ func ImageToString(width, height uint, img image.Image) (string, error) {
b := img.Bounds()
w := b.Max.X
h := b.Max.Y
p := termenv.ColorProfile()
str := strings.Builder{}
for y := 0; y < h; y += 2 {
for x := w; x < int(width); x = x + 2 {
str.WriteString(" ")
}
for x := 0; x < w; x++ {
c1, _ := colorful.MakeColor(img.At(x, y))
color1 := p.Color(c1.Hex())
color1 := lipgloss.Color(c1.Hex())
c2, _ := colorful.MakeColor(img.At(x, y+1))
color2 := p.Color(c2.Hex())
str.WriteString(termenv.String("▀").
Foreground(color1).
Background(color2).
String())
color2 := lipgloss.Color(c2.Hex())
str.WriteString(lipgloss.NewStyle().Foreground(color1).
Background(color2).Render("▀"))
}
str.WriteString("\n")
}

return str.String(), nil
}

Expand Down

0 comments on commit 82a4589

Please sign in to comment.