1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
package vaxis_test
import (
"image/png"
"os"
"git.sr.ht/~rockorager/vaxis"
)
func ExampleImage() {
// Open our image
f, err := os.Open("/home/rockorager/pic.png")
if err != nil {
panic(err)
}
// Decode into an image.Image
img, err := png.Decode(f)
if err != nil {
panic(err)
}
vx, err := vaxis.New(vaxis.Options{})
if err != nil {
panic(err)
}
// Create a graphic with Vaxis. Depending on the terminal, this will
// either send the graphic to the terminal or create a sixel encoded
// version of the image
vimg, err := vx.NewImage(img)
if err != nil {
panic(err)
}
// Resize to whatever size we want, in cell values
w := 20
h := 10
vimg.Resize(w, h)
// Create a window. The window should fully contain the image
win := vx.Window().New(0, 0, w, h)
// Draw the graphic in the window
vimg.Draw(win)
vx.Render()
}
|