lipgloss
lipgloss copied to clipboard
feat: mosaic (halfblocks graphics) support
Original PR: https://github.com/charmbracelet/x/pull/387
Convert images to strings using half blocks symbols
TODO
- [x] Rework API to
mosaic.New().Width(100).Height(40).Render(img) - [x] Use
draw.Scaler - [x] Use
draw.FloydSteinberg
Added examples
Simple Example
func main() {
dogImg, err := loadImage("./pekinas.jpg")
if err != nil {
fmt.Print(err)
os.Exit(1)
}
m := mosaic.New().Width(80).Height(80).Scale(2)
fmt.Println(lipgloss.JoinVertical(lipgloss.Right, lipgloss.JoinHorizontal(lipgloss.Center, m.Render(dogImg))))
}
Scaling
Scales uses bilinear, which works at least as well as the others do in every situation. So prob use Bilinear for upscaling and downscaling as default.
scaling 1x and 2x:
Other examples
Regarding mosaic, I think would be good to support MaxWidth and MaxHeight, so people can create constraints for one or both and allow mosaic do the image perspective calculation cc @aymanbagabas @meowgorithm .
The new width/height API forces the dev to write the exact (or approximate) width/height and it can be quite tedious/unhandy job.