ansify

package module
v0.0.0-...-1446284 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: MIT Imports: 9 Imported by: 0

README

Ansify

Ansify is a Go package that converts PNG and JPEG images into ANSI terminal art. It automatically resizes images to fit your terminal width while maintaining aspect ratio, and renders them using colored block characters for a visually appealing result.

I mostly made this as I needed something exactly like it in order to properly complete a TUI game I'm working on :)

Features

  • Supports PNG and JPEG image formats
  • Automatically resizes images to fit terminal width
  • Maintains aspect ratio during resizing
  • Uses RGB color codes for accurate color representation
  • Smooth image scaling using Catmull-Rom algorithm
  • Returns the image as a string or prints directly to terminal

Installation

go get github.com/ZachLTech/ansify

Usage

Basic Example
package main

import (
    "fmt"
    "github.com/ZachLTech/ansify"
)

func main() {
    // Print image directly to terminal
    ansify.PrintAnsify("path/to/your/image.jpg")

    // Or get the ANSI string to use elsewhere
    ansiString := ansify.GetAnsify("path/to/your/image.png")
    fmt.Print(ansiString)
}
Functions
PrintAnsify(imageInput string)

Loads the image, processes it, and prints directly to the terminal.

GetAnsify(imageInput string) string

Returns the processed image as an ANSI string that can be used elsewhere in your application.

How It Works

  1. The image is loaded and decoded based on its file extension (.png or .jpg/.jpeg)
  2. The image is resized to match your terminal width while maintaining aspect ratio
  3. Each pixel is converted to RGB values and mapped to ANSI color codes
  4. The image is rendered using full block characters (█) with appropriate colors
  5. Each pair of vertical pixels is combined into a single block to maintain proper aspect ratio in the terminal

Limitations

  • Only supports PNG and JPEG formats
  • Requires a terminal that supports RGB ANSI color codes
  • Image quality depends on terminal font, size, and color support

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project falls under the MIT license available here

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAnsify

func GetAnsify(imageInput string) (string, error)

func GetAnsifyCustomWidth

func GetAnsifyCustomWidth(imageInput string, termWidth int) (string, error)

func PrintAnsify

func PrintAnsify(imageInput string) error

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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