| 1 |
// Package main demonstrates usage. |
| 2 |
package main |
| 3 |
|
| 4 |
import ( |
| 5 |
"fmt" |
| 6 |
"image" |
| 7 |
"image/jpeg" |
| 8 |
"os" |
| 9 |
|
| 10 |
"github.com/charmbracelet/lipgloss" |
| 11 |
"github.com/charmbracelet/x/mosaic" |
| 12 |
) |
| 13 |
|
| 14 |
func main() { |
| 15 |
dogImg, err := loadImage("./pekinas.jpg") |
| 16 |
if err != nil { |
| 17 |
fmt.Print(err) |
| 18 |
os.Exit(1) |
| 19 |
} |
| 20 |
|
| 21 |
m := mosaic.New().Width(80).Height(40) |
| 22 |
|
| 23 |
fmt.Println(lipgloss.JoinVertical(lipgloss.Right, lipgloss.JoinHorizontal(lipgloss.Center, m.Render(dogImg)))) |
| 24 |
} |
| 25 |
|
| 26 |
func loadImage(path string) (image.Image, error) { |
| 27 |
f, err := os.Open(path) |
| 28 |
defer f.Close() //nolint:errcheck,staticcheck |
| 29 |
if err != nil { |
| 30 |
return nil, err //nolint:wrapcheck |
| 31 |
} |
| 32 |
return jpeg.Decode(f) //nolint:wrapcheck |
| 33 |
} |