icat

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2025 License: MIT Imports: 23 Imported by: 1

README

icat

Go version of image cat (or imgcat) with bmp, riff,tiff, vp8, vp8l, webp and (optional) HEIF image support (on top of standard Go images formats gif, jpg, png) and URL support and fallback to ASCII art. PrintImageFile and PrintImageURL will print the image to the terminal, trying to figure out which terminal you are using and fallback to ASCII art if the terminal does not support images.

Cmd line version

Installation
go install github.com/hilli/icat/cmd/icat@latest
# With HEIF support:
go install -tags heif github.com/hilli/icat/cmd/icat@latest

Note: To enable heif support, you need to have libheif installed on your system. On macOS, you can install it via Homebrew:

brew install libheif

On Ubuntu, you can install it via apt:

sudo apt install libheif-dev

but you will also probably need to downgrade the version used in icat before compilation. Ie installing libheif on Ubuntu 24.10 will [currently] give you version 1.18.1:

go get github.com/strukturag/libheif@v1.18.1

and then you can install icat with heif support:

go install --tags=heif cmd/icat/icat.go
ls -l $(go env GOPATH)/bin/icat

libheif should be available on most package managers.

Alternatively, you can download the binary from the releases page or install via Homebrew:

brew install hilli/tap/icat

which unfortunately does not support the heif files (Cross compilation is hard with C extensions, mkay).

CLI Usage
icat image.jpg
# Or
icat https://example.com/image.png

Library

Library Usage
package main

import (
  "fmt"
  "os"

  "github.com/hilli/icat"
)

func main() {
  err := icat.PrintImageFile("image.jpg")
  if err != nil {
    fmt.Println(err)
  }
}

LICENSE

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToASCII added in v0.0.7

func ConvertToASCII(img image.Image) string

ASCII art conversion

func ConvertToPaletted added in v0.0.7

func ConvertToPaletted(img image.Image) *image.Paletted

ConvertToPaletted converts an image.Image to an image.Paletted Needed for Sixel conversion

func DecodeImage

func DecodeImage(imageData []byte) (*image.Image, error)

func PrintImage

func PrintImage(img *image.Image, filename string, imageSize int64, forceASCII bool) error

func PrintImageFile

func PrintImageFile(imageFileName string, forceASCII bool) error

func PrintImageURL

func PrintImageURL(imageURL string, forceASCII bool) error

func TermSize

func TermSize() (rows, columns, pixelWith, pixelHeight uint16)

TermSize returns the size of the terminal in rows and columns, as well as the pixel width and height. The latter might not be supported on all terminals. If the terminal size cannot be determined, it returns (0, 0, 0, 0).

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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