asciize

package module
v0.0.0-...-e121a8f Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2017 License: MIT Imports: 8 Imported by: 0

README

Asciize

This is a port to pure go of the original ruby gem asciiart

Installation

If you want to install the binary, just go to the releases page and download the latest available for your system.

If you have go installed:

To install only the cli:

$ go get -u github.com/marc-gr/asciize/cmd/asciize

To also install the code:

$ go get -u github.com/marc-gr/asciize

Usage

In Code
f, _ := os.Open("./sample.png")
img, err := png.Decode(f)
if err != nil {
	panic(err)
}
a := asciize.NewAsciizer(asciize.Colored(true))
s, err := a.Asciize(img)
if err != nil {
	panic(err)
}
fmt.Println(s)

For more go to the examples folder

In The Command Line

Local Files

$ asciize -src "examples/sample.png"
                                           oooooooooooooooo                                          
                                 oo%%%###########################%%oo                                
                           oo%#########################################%oo                           
                       o%###################################%%ooooo%%######%o     oooooo             
         oo%%%%oo   o%####%%oo%%%%%ooo%#################%oo%%MWWWWWM%%oo%#####%oo#########o          
      o%########%oo####%oo%MWWWWWWWWWW%%o%############oo%WWWWWWWWWWWWWWW%o%#####%o%#%#######o        
     %#####%###oo####%o%WWWWWWWWWWWWWWWWW%o%########%oMWWWWWWWWWWWWWWWWWWW%o######o   o######o       
    %####o    o%####o%WWWWWWWWWWWWWWWWWWWWWo%######%oWWWWWWWWWWWWWWWWWWWWWW%o######%   o######       
   o####o    o#####%oWWWM%%MWWWWWWWWWWWWWWWWo######oWWWoo  oMWWWWWWWWWWWWWWWo#######% o#######       
    ####%o  o######oWWM      MWWWWWWWWWWWWWWo%####%oWW       MWWWWWWWWWWWWWWo%#######%o######o       
    o#####%o#######oWWo    o oWWWWWWWWWWWWWW%o####%oWW    oM %WWWWWWWWWWWWWWo%########%o###%o        
      %###o%#######oMW%    %o%WWWWWWWWWWWWWWo%#####oMW%     %WWWWWWWWWWWWWWMo##########ooo           
         oo########%oWWMooooMWWWWWWWWWWWWWW%o######%oMWWMMMWWWWWWWWWWWWWWWMo%##########%             
          ##########%oWWWWWWWWWWWWWWWWWWWW%o####%%%##o%WWWWWWWWWWWWWWWWWMoo#############o            
         o###########%o%WWWWWWWWWWWWWWWM%o%#%o       o%oo%MWWWWWWWWWWM%oo###############%            
         %#############%oo%%MWWWWWWM%%oo%##%           ##%%ooo%%%%ooo%###################            
         ##################%%oooooo%%###%oo%          %%o%###############################o           
         ##############################%o%%%%%%%%%%%%%%%%%o%#############################o           
        o##############################o%%%%%%%%%%%%%%%%%%%o%############################%           
        o##############################oo%%%%%%%%o%%%%%%%%%o##############################           
        o###############################%ooo%%MW%oWWM%oooo%###############################           
        o#################################o%WWWWo%WWWWo###################################           
        o#################################%oWWWWo%WWWWo###################################o          
         ##################################ooMM%oo%WM%o###################################o          
         ###################################%%%%##%oo%####################################o          
         %################################################################################o          
         %################################################################################o          
         o################################################################################o          
         o################################################################################o          
          ################################################################################o          
          ################################################################################o          
          ################################################################################o          
          %###############################################################################o          
          %###############################################################################o o        
   o%%%%%o%###############################################################################%o%%%%%o   
 %%%%%%%%o%###############################################################################%o%%%%%%%  
 oo%%%%%% %################################################################################ %%%%%oo  
  %%%o    %################################################################################    ooo   
          #################################################################################o         
          #################################################################################o         
         o#################################################################################o         
         o#################################################################################o         
         %#################################################################################o         
         %#################################################################################%         
         ##################################################################################%         
         ##################################################################################%         
         ##################################################################################o         
         ##################################################################################o         
         ##################################################################################o         
         ##################################################################################          
         ##################################################################################          
         %################################################################################o          
         o################################################################################           
         o###############################################################################%           
          %##############################################################################            
          o#############################################################################o            
           %###########################################################################%             
            %#########################################################################%              
             %#######################################################################%               
              o#####################################################################o                
                %#################################################################%                  
                 o%#############################################################%o                   
                 o%oo########################################################%oo%%%o                 
              o%%%%%%ooo%#################################################%oo%%%%%%%%o               
             %%%%%%%%%%%o oo%########################################%%o     %%%%%%%%%o              
            %%o%%%%%%%o         oo%%%#########################%%ooo            %%%%%o%%              
            oo%%%%%%                      oooooooooooooo                         %%%%                
              o%o                                                                                    
                                                                                                     

Remote Images

 $ asciize -src "http://www.google.com/images/srpr/logo3w.png"

Output it as HTML

$ asciize -c -f html -src "examples/sample.png" > ascii-as-html.html

or smaller

$ asciize -w 50 -c -f html -src "examples/sample.png" > ascii-as-html.html

Get Help

Usage of ./asciize:
  -c	If set to true the output will be colored (ANSI or HTML)
  -cs string
    	Used to define a custom charset (default " .~:+=o*x^%#@$MW")
  -f string
    	Output format. Can be "text" or "html" (default "text")
  -i	If set to true the charset will be reversed. Can improve results for some images
  -src string
    	Define the source of the image. Can be a local file or a URL
  -w uint
    	Target width (default 100)

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Documentation

Overview

Package asciize provides methods and types to transform images to ASCII art.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultCharset

func DefaultCharset() []byte

DefaultCharset returns the default charset " .~:+=o*x^%#@$MW".

Types

type Asciizer

type Asciizer struct {
	// contains filtered or unexported fields
}

Asciizer allows to transform any image into its ASCII art representation with a set of configurable options.

func NewAsciizer

func NewAsciizer(opts ...Option) *Asciizer

NewAsciizer initialize a new asciizer with the given options.

func (*Asciizer) Asciize

func (a *Asciizer) Asciize(m image.Image) (ascii string, err error)

Asciize receives an image and transforms it to an ASCII art representation.

type Option

type Option func(*Asciizer)

Option is a type defining functions that can change Asciizer behavior.

func Charset

func Charset(charset []byte) Option

Charset defines what charset is being used to transform images.

func Colored

func Colored(c bool) Option

Colored indicates the output will be colored in the specified format (ANSI for text or HTML).

func Format

func Format(f OutputFormat) Option

Format indicates what the format to output will be, can be "text" or "html".

func InvertCharset

func InvertCharset(i bool) Option

InvertCharset allows to enable or disable inverted charset. This can make the result clearer in some images.

func Width

func Width(w uint) Option

Width sets the output target width.

type OutputFormat

type OutputFormat string

OutputFormat represents a supported output format. i.e.: text, html

const (
	// FormatText represents plain text output format
	FormatText OutputFormat = "text"
	// FormatHTML represents HTML representation of the ASCII art
	FormatHTML OutputFormat = "html"
)

Directories

Path Synopsis
cmd
examples

Jump to

Keyboard shortcuts

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