Skip to content

Commit

Permalink
Update image_preview.go
Browse files Browse the repository at this point in the history
Fix transparent background in images
  • Loading branch information
JassonCordones authored Sep 9, 2024
1 parent 5228cd3 commit c3e985e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/pkg/file_preview/image_preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ func ConvertImageToANSI(img image.Image, defaultBGColor color.Color) string {
// colorToTermenv converts a color.Color to a termenv.RGBColor
func colorToTermenv(c color.Color, fallbackColor string) termenv.RGBColor {
r, g, b, a := c.RGBA()
if a == 0 && fallbackColor != "" {
return termenv.RGBColor(fallbackColor)
}

if a == 0 {
return termenv.RGBColor("")
}
return termenv.RGBColor(fmt.Sprintf("#%02x%02x%02x", uint8(r>>8), uint8(g>>8), uint8(b>>8)))
}

Expand Down

0 comments on commit c3e985e

Please sign in to comment.