asciiart

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: MIT Imports: 10 Imported by: 0

README

asciiart

The asciiart package is a Go library for generating ASCII art from images.

What is ASCII art?

ASCII art is a form of artistic expression where images are created using only the characters from the ASCII standard, which includes letters, numbers, and symbols. Originating in the early days of computing, it transforms plain text into visual designs, ranging from simple line art to complex compositions. ASCII art remains popular for its unique aesthetic and is used in various digital platforms and software environments to add creativity and visual interest.

Features

  • Supports JPEG and PNG image formats.
  • Generates ASCII art from base64-encoded image data.
  • Supports custom encoding types (standard and URL encoding).

Installation

go get -u github.com/yudai2929/asciiart

Usage

Generate ASCII Art from an Image File
package main

import (
	"fmt"
	"log"
	"os"
	"github.com/yudai2929/asciiart"
)

func main() {
	file, err := os.Open("path/to/your/image.jpg")
	if err != nil {
		log.Fatalf("Failed to open file: %v", err)
	}
	defer file.Close()

	// Generate ASCII art with default settings
	asciiArt, err := asciiart.Generate(file)
	if err != nil {
		log.Fatalf("Failed to generate ASCII art: %v", err)
	}
	fmt.Println("Default ASCII Art:")
	fmt.Println(asciiArt)

	// Generate ASCII art with custom width and character set
	customASCIIArt, err := asciiart.Generate(file, asciiart.WithWidth(150), asciiart.WithAASet("@#%*+=-:. "))
	if err != nil {
		log.Fatalf("Failed to generate ASCII art with custom settings: %v", err)
	}
	fmt.Println("Custom ASCII Art:")
	fmt.Println(customASCIIArt)
}
Generate ASCII Art from a Base64 Encoded Image
asciiArt, err := asciiart.GenerateFromBase64(encodedString, asciiart.StdEncoding)
if err != nil {
	log.Fatalf("Failed to generate ASCII art: %v", err)
}
fmt.Println(asciiArt)
ASCII Art Example

Below is a link to an example of the ASCII art output generated by the asciiart package. This example demonstrates the kind of visual representation you can achieve with the default settings:

Options
  • WithWidth(int): Set a custom width for the ASCII art. Valid values range between 50 and 200.
  • WithAASet(string): Set a custom ASCII character set for generating the art. The length of the character set must be between 4 and 64 characters.

Contributions

Contributions are welcome! Please feel free to submit pull requests, report bugs, or suggest new features.

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 Generate

func Generate(reader io.Reader, opts ...Option) (string, error)

Generate generates ASCII art from an image.

func GenerateFromBase64

func GenerateFromBase64(encodedString string, encodingType EncodingType, opts ...Option) (string, error)

GenerateFromBase64 generates ASCII art from a base64 encoded image.

Types

type EncodingType

type EncodingType string

EncodingType represents the encoding type of the base64 encoded image.

const (
	// StdEncoding represents the standard encoding type.
	StdEncoding EncodingType = "std"
	// URLEncoding represents the URL encoding type.
	URLEncoding EncodingType = "url"
)

type Option

type Option func(*options)

Option represents the option to customize the ASCII art.

func WithAASet

func WithAASet(aaSet string) Option

WithAASet sets the ASCII art set.

func WithWidth

func WithWidth(width int) Option

WithWidth sets the width of the ASCII art.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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