dots

package module
v0.0.0-...-67dc0cc Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

README

dots

Go Reference

Convert images to braille art in the terminal with ANSI colors.

$ dots -w 40 testdata/rainbow_gradient.png
$ go run ./cmd/dots -w 80 -threshold 115 avatar.jpeg

Install

go install github.com/imjasonh/dots/cmd/dots@latest

CLI Usage

# Auto-fit to terminal, maintain aspect ratio
dots image.png

# Specify width (height calculated from aspect ratio)
dots -w 80 image.png

# Specify both dimensions
dots -w 80 -h 40 image.png

# Add background color
dots -background ff0000 image.png

Library Usage

import "github.com/imjasonh/dots"

img, _ := loadImage("photo.png")
lines := dots.Convert(img, dots.Options{
    Width:  80,
    Height: 40,
})
for _, line := range lines {
    fmt.Println(line)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateDimensions

func CalculateDimensions(imgWidth, imgHeight, width, height, maxWidth, maxHeight int) (int, int)

CalculateDimensions calculates output dimensions maintaining aspect ratio. If both width and height are specified, returns them unchanged. If only width is specified, calculates height from image aspect ratio. If only height is specified, calculates width from image aspect ratio. If neither is specified, uses maxWidth and maxHeight as constraints while maintaining aspect ratio.

The calculation accounts for braille characters being 2 pixels wide × 4 pixels tall.

func Convert

func Convert(img image.Image, opts Options) []string

Convert converts an image to braille representation. Returns a slice of strings, one per line of output.

func ParseHex

func ParseHex(hex string) (uint8, error)

ParseHex parses a hex color string (with or without #) and returns the ANSI 256 color code. Supports both 3-character shorthand (e.g., "f00") and 6-character full format (e.g., "ff0000").

Types

type Options

type Options struct {
	Width           int    // Width in braille characters
	Height          int    // Height in braille characters
	Threshold       uint8  // Brightness threshold (0-255), default 20
	NoColor         bool   // Disable ANSI color output
	BackgroundColor *uint8 // Background color for ANSI output (nil = no background)
	Frame           bool   // Draw a white ASCII frame around the picture
}

Options configures the braille conversion.

Directories

Path Synopsis
cmd
dots command

Jump to

Keyboard shortcuts

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