reisen

module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2023 License: MIT

README

:reisen_overdrive: Reisen

Reisen is a library that converts images into ASCII images and provides command-line tools for easy use.

Installation

go install marisa.chaotic.ninja/reisen/cmd/reisen@latest

CLI usage

reisen version: reisen/1.1.0
>> HomePage: https://marisa.chaotic.ninja/reisen
>> Issue   : mailto:devel@chaotic.ninja?Subject=[reisen-devel]
>> Author  : qeesung, Izuru Yakumo
Usage: reisen [-s] -f <filename> -r <ratio> -w <width> -g <height>

Options:
  -c    Colored the ascii when output to the terminal (default true)
  -f string
        Image filename to be convert (default "docs/images/lufei.jpg")
  -g int
        Expected image height, -1 for image default height (default -1)
  -i    Reversed the ascii when output to the terminal
  -r float
        Ratio to scale the image, ignored when use -w or -g (default 1)
  -s    Fit the terminal screen, ignored when use -w, -g, -r (default true)
  -t    Stretch the picture to overspread the screen
  -w int
        Expected image width, -1 for image default width (default -1)

Library usage

package main

import (
	"fmt"
	"marisa.chaotic.ninja/reisen/convert"
	_ "image/jpeg"
	_ "image/png"
)

func main() {
	// Create convert options
	convertOptions := convert.DefaultOptions
	convertOptions.FixedWidth = 100
	convertOptions.FixedHeight = 40

	// Create the image converter
	converter := convert.NewImageConverter()
	fmt.Print(converter.ImageFile2ASCIIString(imageFilename, &convertOptions))
}

convert options

type Options struct {
	Ratio           float64 // convert ratio
	FixedWidth      int  // convert the image width fixed width
	FixedHeight     int  // convert the image width fixed height
	FitScreen       bool // only work on terminal, fit the terminal height or width
	StretchedScreen bool // only work on terminal, stretch the width and heigh to overspread the terminal screen
	Colored         bool // only work on terminal, output ascii with color
	Reversed        bool // if reverse the ascii pixels
}

supported convert function

type Converter interface {
	// convert a image object to ascii matrix
	Image2ASCIIMatrix(image image.Image, imageConvertOptions *Options) []string
	// convert a image object to ascii matrix and then join the matrix to a string
	Image2ASCIIString(image image.Image, options *Options) string
	// convert a image object by input a string to ascii matrix
	ImageFile2ASCIIMatrix(imageFilename string, option *Options) []string
	// convert a image object by input a string to ascii matrix then join the matrix to a string
	ImageFile2ASCIIString(imageFilename string, option *Options) string
}

License

This project is under the MIT License. See the LICENSE file for the full license text.

Credits

Directories

Path Synopsis
Package ascii can convert a image pixel to a raw char base on it's RGBA value, in another word, input a image pixel output a raw char ascii.
Package ascii can convert a image pixel to a raw char base on it's RGBA value, in another word, input a image pixel output a raw char ascii.
cmd
Package convert can convert a image to ascii string or matrix
Package convert can convert a image to ascii string or matrix

Jump to

Keyboard shortcuts

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