im2ascii

package module
v0.0.0-...-2c7eea5 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2024 License: MIT Imports: 7 Imported by: 0

README

GO Package for Image to ASCII in color

This is a simple package that converts an image to ASCII in color that can be printed to the terminal. It was created by pair programming with GPT4 as I needed something simple, yet beautiful ascii art generator for another project.

Since the package returns the ASCII image as a slice of strings, you can easily print it to the terminal or save it to a file. It is also possible to have your own texts printed either to the right or left of the image by appending the text to the slice of strings.

Inspiration for this package came from image-to-ascii-art ascii-image-converter

Features

  • Convert an image to ASCII in color
  • Maintains aspect ratio of the original image
  • Returns the ASCII image as a slice of strings
  • Provides a loading function for image paths

Installation

If you want to use this package in your go project, you can install it using the following command:

go get github.com/1-ashraful-islam/image2ascii

Usage

package main

import (
  "fmt"

  im2ascii "github.com/1-ashraful-islam/image-to-ascii"
)

func main() {
  //load image
  img, err := im2ascii.LoadImage("path/to/image.jpg")
  if err != nil {
    fmt.Println(err)
    return
  }
  //create ascii image
  asciiImage, err := im2ascii.CreateASCIIImage(img, 80, 80)
  if err != nil {
    fmt.Println(err)
    return
  }
  //print ascii image
  for _, line := range asciiImage {
    fmt.Println(line)
  }
}

Testing

To run the tests, you can use the following command:

go test ./... -v -cover

Example output

Original Image ASCII Image
Pikachu Pikachu ASCII
Mona Lisa Mona Lisa ASCII
Toy Story Toy Story ASCII

Original Images (left column) used in the examples are not property of the author and were taken from the internet. They are used for educational purposes only.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateASCIIImage

func CreateASCIIImage(img image.Image, width, height int) ([]string, error)

func LoadImage

func LoadImage(imagePath string) (image.Image, error)

Types

This section is empty.

Jump to

Keyboard shortcuts

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