goscii

package module
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 2 Imported by: 0

README

GOSCII

library and cli for convert image to ASCII art

Installation

# package
go get github.com/Perkovec/goscii

# cli
go install github.com/Perkovec/goscii/cli/goscii

CLI usage

goscii [args]
Argument Default Description
-h help
-i input image file
-c 0 output columns (0 - terminal width)
-r 0 output rows (0 - terminal height)
-f contain fit algorithm (contain, cover, height, width, fill)

Package methods

NewConverter

Create new converter instance with options

package main

import (
    "fmt"
    "github.com/Perkovec/goscii"
)

func main() {
    converter, err := goscii.NewConverter()
}
Convert

Convert image to ASCII art

package main

import (
    "fmt"
    "github.com/Perkovec/goscii"
    "image"
    "os"
    _ "image/jpeg"
)

func main() {
    converter, err := goscii.NewConverter()
    if err != nil {
        panic(err)
    }

    imageFile, err := getImageFromFilePath("image.jpg")
    if err != nil {
        panic(err)
    }

    artRows := converter.Convert(imageFile)
   
    for _, row := range artRows {
        fmt.Println(row)
    }
}

func getImageFromFilePath(filePath string) (image.Image, error) {
	f, err := os.Open(filePath)
	if err != nil {
		return nil, err
	}
	defer f.Close()
	image, _, err := image.Decode(f)
	return image, err
}

Documentation

Overview

library and cli for convert image to ASCII art

Index

Constants

View Source
const (
	FontAspectRatio = 0.5 // according to https://terminus-font.sourceforge.net/
)

Variables

View Source
var (
	CharsetBlock   = Charset("█")
	CharsetDefault = Charset(" .,:;i1tfLCG08@")
)

Functions

func NewConverter

func NewConverter(options ...GOSCIIConverterOptions) (*goSCIIConverter, error)

Create new converter

Types

type Charset

type Charset []byte

type Fit

type Fit int8
const (
	FitWidth Fit = iota + 1
	FitHeight
	FitCover
	FitContain
	FitFill
)

type GOSCIIConverter

type GOSCIIConverter interface {
	Convert(img image.Image) []byte
}

type GOSCIIConverterOptions

type GOSCIIConverterOptions struct {
	// Charset to use
	Charset Charset
	// Output columns
	Columns int
	// Output rows
	Rows int
	// Output resize algorithm
	Fit Fit
	// Font aspect ratio
	FontAspectRatio float64
}

Converter options

func (*GOSCIIConverterOptions) Merge

func (dest *GOSCIIConverterOptions) Merge(source GOSCIIConverterOptions)

Directories

Path Synopsis
cli

Jump to

Keyboard shortcuts

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