timg

package module
v0.0.0-...-8a378ff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2023 License: Unlicense Imports: 8 Imported by: 1

README

timg

A simple to use terminal image renderer.

  • uses unicode characters over double the width for images

TODO

[ ] determine a good pre-alloc size [ ] transparent background of image [ ] toggle between ascii only ' ' and '▀' [ ] all the ansi, ansi256 and true color have a lot of shared code

Examples

Render image as is in it's original size
var img image.Image

img = ... // load image

// render the image (turn it to a string)
// Note:  timg.Render will auto detect what color
//        profile the environment supports (using termenv)
println(timg.Render(img))
Render image but make it fit a certain size
var img image.Image

img = ... // load image

// resize image to fit in a 25x25 cell box
println(timg.Render(img, timg.FitTo(25, 25))
Other examples

see ./examples

$ cd ./examples
$ go run ./resize/main.go /path/to/your/image

References

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(img image.Image, opts ...RenderOption) string

Render returns the string representing the rendered image taking the RenderOptions into account.

Types

type RenderOption

type RenderOption func(o *opt)

func FitScreen

func FitScreen() RenderOption

FitToScreen tries to figure out the dimentions of the terminal (on stdout). If this fails ... no image dimensions are set. This is so that the image rendering can never fail. If you are unsure about this behavior just use FitTo.

func FitTo

func FitTo(width, height int) RenderOption

FitTo is an option to make the image fit into the box defined by width and height

func WithColorProfile

func WithColorProfile(profile termenv.Profile) RenderOption

WithColorProfile is an option that makes Render use the given profile instead of querying the terminal(emulator) for what it supports.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL