asciiconverter

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

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

Go to latest
Published: Jul 26, 2025 License: MIT Imports: 9 Imported by: 0

README

ASCII Image & GIF Converter

This Go package converts images and GIFs into colored ASCII art that can be displayed directly in the terminal. It supports both single images and animated GIFs, resizing them while preserving aspect ratio and applying ANSI 24-bit color codes (TrueColor) for a vivid result.

Features

  • Image to ASCII Conversion: Converts any image to ASCII art with color.
  • GIF to ASCII Conversion: Supports animated GIFs, generating ASCII frames with correct delays.
  • Automatic Resizing:
    • Set both width and height explicitly, or
    • Provide only width or only height (set the other to 0) and the aspect ratio is automatically preserved.
  • Terminal Animation: Plays ASCII GIFs directly in the terminal with proper frame timing.
  • Custom Character Set: Uses a defined character set for luminance-based ASCII mapping (Rec. 601).

Installation

go get github.com/mattparadis/asciiConverter

Usage

Convert a Single Image
package main

import (
    "fmt"
    "log"
    "asciiconverter"
)

func main() {
    // Example: specify only width (height is auto-calculated)
    img, err := asciiconverter.GetAsciiImage("path/to/image.jpg", 100, 0)
    if err != nil {
        log.Fatal(err)
    }
    asciiconverter.PrintImg(img)
}
Convert and Play a GIF
package main

import (
    "log"
    "asciiconverter"
)

func main() {
    // Example: specify only height (width is auto-calculated)
    frames, err := asciiconverter.GetAsciiGif("path/to/animation.gif", 0, 40)
    if err != nil {
        log.Fatal(err)
    }
    asciiconverter.PrintGif(frames, 3) // Play 3 loops
}

API Overview

GetAsciiImage(path string, width, height int) ([]string, error)
  • Converts a single image to ASCII lines.
  • If width or height is 0, aspect ratio is preserved automatically.
GetAsciiGif(path string, width, height int) ([]*AsciiGif, error)
  • Converts a GIF into a slice of ASCII frames, each with delay information.
PrintImg(img []string)
  • Prints a single ASCII image.
PrintGif(frames []*AsciiGif, loop int)
  • Plays an ASCII GIF animation in the terminal, looping loop times.

Requirements

License

This project is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAsciiImage

func GetAsciiImage(path string, width, height int) ([]string, error)

GetAsciiImage converts a single image from the specified path into ASCII art. The output is a slice of strings representing the ASCII image. width or height can be set to 0 to automatically preserve aspect ratio.

func PrintGif

func PrintGif(frames []*AsciiGif, loop int)

PrintGif plays an ASCII GIF animation in the terminal. The parameter 'loop' specifies the number of times the animation should repeat.

func PrintImg

func PrintImg(img []string)

PrintImg prints a single ASCII image to the terminal.

Types

type AsciiGif

type AsciiGif struct {
	Lines []string
	Delay time.Duration
}

func GetAsciiGif

func GetAsciiGif(path string, width, height int) ([]*AsciiGif, error)

GetAsciiGif converts a GIF from the specified path into a slice of AsciiGif frames. Each frame contains ASCII art lines and its display delay. width or height can be set to 0 to automatically preserve aspect ratio.

Jump to

Keyboard shortcuts

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