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.