gotermimg

package module
v0.0.0-...-045552a Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2023 License: MIT Imports: 6 Imported by: 0

README

gotermimg

Build Status

Something hacked together to display images and play gifs in 256 color terminals. I have implemented something similar before , as have others...

Wrote this largely as an exercise in Go.

Installation

Install using go get:

go get github.com/moshen/gotermimg/...

Installs the gotermimg command line application.

Usage

gotermimg
Usage: gotermimg [-u] [-x=n] [-y=n] [-l=n|-s=n] [IMAGEFILE]
  IMAGEFILE - png, gif or jpg.  gif will auto-play.
  Image data can be piped to stdin instead of providing IMAGEFILE.

  If neither -x or -y are provided, and the image is larger than your current
  terminal, it will be automatically scaled to fit.

  -l=0: Loop animation n times
        When -l=0 (the default), animation is looped indefinitely. Supersedes -s
        Only applies to multi-frame gifs
  -s=0: Loop animation n seconds
        When -s=0 (the default), this option is ignored.
        Only applies to multi-frame gifs
  -u=false: Enable UTF8 output
  -x=0: Scale to n*2 columns wide in ANSI mode, n columns wide in UTF8 mode.
        When -x=0 (the default), aspect ratio is maintained.
        For example if -y is provided without -x, width is scaled to
        maintain aspect ratio
  -y=0: Scale to n rows high in ANSI mode, n/2 rows high in UTF8 mode.
        When -y=0 (the default), aspect ratio is maintained.
        For example if -x is provided without -y, height is scaled to
        maintain aspect ratio

gotermimg on a png with transparency

gotermimg on an animated gif with transparency

While the render speed on some slower terminals might not look very good, urxvt looks amazing (click through for HQ).

gotermimg on urxvt

Author

Colin Kennedy

vendor/gif

Go AUTHORS

vendor/resize

Jan Schlicht

vendor/termutil

Andrew

License

MIT (unless otherwise noted), See LICENSE file

The Go gopher was designed by Renee French. (http://reneefrench.blogspot.com/) The design is licensed under the Creative Commons 3.0 Attributions license. Read this article for more details: http://blog.golang.org/gopher

vendor/gif

BSD

vendor/resize

MIT Style

vendor/termutil

MIT

Documentation

Overview

Package gotermimg provides functions to convert image.Image structs to 256 color terminal compatible []string. It also provides functions to convert and "play" gif animations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ANSI

func ANSI(img image.Image, trans Transformer) []string

Converts image.Image img to a []string of 256 color terminal compatbile ANSI using 2 spaces as a "pixel". Applies Transformer trans to img before conversion

func PrintAnimation

func PrintAnimation(ani Animation, loop KeepLooping)

Prints Animation ani to os.Stdout after clearing the terminal Does not return unless loop() returns false

func PrintImage

func PrintImage(img image.Image, conv Converter, trans Transformer)

Prints image.Image img to os.Stdout using Converter with Transformer trans

func UTF8

func UTF8(img image.Image, trans Transformer) []string

Converts image.Image img to a []string of 256 color terminal compatbile UTF8 using UTF8 1/2 blocks as a "pixel". Applies Transformer trans to img before conversion

Types

type Animation

type Animation []Frame

func Gif

func Gif(g *gif.GIF, conv Converter, trans Transformer) Animation

Converts *git.GIF g to an Animation using Converter conv Currently assumes all gif frames are the same size

type Converter

type Converter func(image.Image, Transformer) []string

type Frame

type Frame struct {
	ANSI  []string
	Delay time.Duration
}

Defines a frame of an Animation

type KeepLooping

type KeepLooping func() bool

func LoopSeconds

func LoopSeconds(s uint) KeepLooping

Returns true until s seconds have elapsed

func LoopTimes

func LoopTimes(n uint) KeepLooping

Returns true until n calls have been made

type Transformer

type Transformer func(image.Image) image.Image

func Resize

func Resize(width, height uint) Transformer

Directories

Path Synopsis
cmd
Package terminal provides the functions and constants required for 256 color terminal output and the conversion of color.Color structs to ColorCode
Package terminal provides the functions and constants required for 256 color terminal output and the conversion of color.Color structs to ColorCode

Jump to

Keyboard shortcuts

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