ascii

package module
v0.2.0 Latest Latest
Warning

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

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

README

ASCII Art Generator in Go

Go Version License Go Report Card Tests Contributions Welcome

Overview

ascii is a Go library designed to convert images into ASCII art. The library provides a simple and efficient way to generate ASCII representations of images with color support.

Features

  • Image Decoding: Supports multiple image formats including PNG, JPEG, and GIF.
  • Byte Array Support: Operates directly on byte arrays for image manipulation.
  • Image Scaling: Efficiently scales images to fit the ASCII grid.
  • Color Support: Outputs colored ASCII art based on the original image colors.

Installation

Install the package using go get:

go get github.com/alexekdahl/ascii

Usage

Here's a simple example to generate ASCII art from an image:

package main

import (
	"fmt"
	"io"
	"net/http"

	"github.com/alexekdahl/ascii"
)

func main() {
	resp, err := http.Get("https://avatars.githubusercontent.com/u/1024025?v=4")
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()
	body, _ := io.ReadAll(resp.Body)

	customASCII, err := ascii.ToASCII(body, ascii.WithChar('█'))
	if err != nil {
		panic(err)
	}

	defaultASCII, err := ascii.ToASCII(body)
	if err != nil {
		panic(err)
	}

	fmt.Println(customASCII)
	fmt.Println(defaultASCII)
}

Contributing

We welcome contributions!

License

This project is licensed under the MIT License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToASCII

func ToASCII(imgData []byte, opts ...Option) (string, error)

ToASCII converts raw image data to an ASCII art string with a specified style. The image dimensions are scaled down to 'w' and 'h'. ToASCII converts raw image data to an ASCII art string with specified options.

Types

type ASCIIOptions added in v0.2.0

type ASCIIOptions struct {
	Style  ArtStyle
	Char   rune
	Width  int
	Height int
}

ASCIIOptions holds configuration for ASCII generation.

type ArtStyle added in v0.2.0

type ArtStyle int

ArtStyle defines the ASCII art style.

const (
	ColorASCII ArtStyle = iota
	GrayASCII
)

type Option added in v0.2.0

type Option func(*ASCIIOptions)

Option is a function that applies a given configuration to ASCIIOptions.

func WithChar added in v0.2.0

func WithChar(c rune) Option

WithChar sets the ASCII character to be used.

func WithHeight added in v0.2.0

func WithHeight(h int) Option

WithHeight sets the desired height of the ASCII art.

func WithStyle added in v0.2.0

func WithStyle(s ArtStyle) Option

WithStyle sets the style of the ASCII art (color or grayscale).

func WithWidth added in v0.2.0

func WithWidth(w int) Option

WithWidth sets the desired width of the ASCII art.

Jump to

Keyboard shortcuts

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