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.
- 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.
Install the package using go get
:
go get github.com/alexekdahl/ascii
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)
}
We welcome contributions!
This project is licensed under the MIT License - see the LICENSE file for details.