lipgloss icon indicating copy to clipboard operation
lipgloss copied to clipboard

feat: mosaic (halfblocks graphics) support

Open raphamorim opened this issue 9 months ago • 1 comments

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))))
}
Screenshot 2025-03-06 at 13 08 53 Screenshot 2025-03-06 at 13 08 48

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:

Screenshot 2025-03-07 at 13 14 15

Other examples

Screenshot 2025-03-07 at 13 13 11 Screenshot 2025-02-27 at 15 05 53

raphamorim avatar Feb 27 '25 17:02 raphamorim

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.

raphamorim avatar Mar 10 '25 15:03 raphamorim