Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mosaic (halfblocks graphics) support #482

Open
wants to merge 43 commits into
base: v2-exp
Choose a base branch
from

Conversation

raphamorim
Copy link
Member

@raphamorim raphamorim commented Feb 27, 2025

Original PR: charmbracelet/x#387

Convert images to strings using half blocks symbols

TODO

  • Rework API to mosaic.New().Width(100).Height(40).Render(img)
  • Use draw.Scaler
  • 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 raphamorim changed the title feat: halfblocks graphics support feat: mosaic (halfblocks graphics) support Feb 27, 2025
@raphamorim raphamorim changed the base branch from master to v2-exp March 6, 2025 19:36
@raphamorim raphamorim force-pushed the feat-halfblocks-support branch from 92097b0 to 811f6dc Compare March 7, 2025 00:19
@raphamorim raphamorim marked this pull request as ready for review March 7, 2025 00:34
@raphamorim raphamorim requested a review from aymanbagabas March 7, 2025 17:52
@raphamorim raphamorim requested a review from caarlos0 March 7, 2025 18:56
Copy link
Member

@aymanbagabas aymanbagabas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal here is to make both mosaic.New() and mosaic.Mosaic{} return the same thing

@raphamorim raphamorim requested a review from aymanbagabas March 10, 2025 13:15
@raphamorim raphamorim requested a review from aymanbagabas March 10, 2025 15:17
@raphamorim
Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants