A cross-platform image to ASCII art converter written in Go with a hexagonal architecture. The project provides three ways to use the converter:
- As a CLI tool
- As an HTTP server with a web interface
- As a Go module that can be imported into other Go programs
- Convert images (JPEG, PNG) to ASCII art
- Customizable output width and height
- Configurable character set for ASCII art
- Optional colored output (ANSI colors)
- Brightness inversion option
- Output to console or file
- Web interface for easy testing
go install github.com/alandavd/asci/cmd/cli@latest
go install github.com/alandavd/asci/cmd/server@latest
# Basic usage
asci input.jpg
# Customize width
asci -width 120 input.jpg
# Save to file
asci -output result.txt input.jpg
# Enable colored output
asci -color input.jpg
# Invert brightness
asci -invert input.jpg
# Full options
asci -width 120 -height 60 -charset "@%#*+=-:. " -color -invert -output result.txt input.jpg
# Start the server
server
# Server will be available at http://localhost:8080
Visit http://localhost:8080 in your browser to use the web interface.
package main
import (
"os"
"github.com/alandavd/asci/pkg"
)
func main() {
// Create a converter
converter := asci.NewConverter()
// Open an image file
file, _ := os.Open("input.jpg")
defer file.Close()
// Convert with options
result, err := converter.Convert(file,
asci.WithWidth(120),
asci.WithHeight(60),
asci.WithCharset(" .:-=+*#%@"),
asci.WithColor(true),
asci.WithInverted(false),
)
if err != nil {
panic(err)
}
// Print the result
println(result)
}
WithWidth(width int)
: Set the width of the ASCII art outputWithHeight(height int)
: Set the height of the ASCII art output (0 for auto)WithCharset(charset string)
: Set the characters to use for ASCII artWithColor(enabled bool)
: Enable or disable colored outputWithInverted(enabled bool)
: Enable or disable brightness inversion
The project follows a hexagonal architecture pattern:
pkg/
: Public API for external useinternal/core/ports/
: Core interfacesinternal/core/services/
: Business logic implementationcmd/cli/
: CLI applicationcmd/server/
: HTTP server application
MIT License