Skip to content

emptyxl/PyAsciiArt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyAsciiArt

Convert image to character painting

Installation

You can use pip to install this module:

pip install PyAsciiArt

Or download the source code and manual installation:

python setup.py install

Usage

There are two ways to use this module.

1.Use this module as script
python -m PyAsciiArt example.png

The parameters are described below:

PyAsciiArt
    Convert image to character painting.

Usage:
    PyAsciiArt.py <file>... [--contrast C_NUMBER]
                            [--resize WIDTH]
                            [-o OUTPUT_FILE]
                            [-r]
    PyAsciiArt.py (-h | --help)
    PyAsciiArt.py --version

Example:
    PyAsciiArt.py example.png
    PyAsciiArt.py example.png --resize 100 -o result.txt
    PyAsciiArt.py example.png --resize 100 --contrast 0.5 -r

Options:
    --contrast C_NUMBER     Change the image contrast.
    --resize WIDTH          Modify image size, keep proportion by default. The unit is pixel.
    -o OUTPUT_FILE          Output filename.
    -r                      Reverse the result, dark background image may get better result
    -h --help               Show help.
    --version               Show version.
2.Be imported by other module
from PyAsciiArt import PyAsciiArt

PyAsciiArt.convert('example.png', resize=128, contrast=1.5)

The specific usage can see function Annotations.

Example

original image

image

example1

python -m PyAsciiArt example.png --resize 128 
=========================================;=;;;;;;;;;;;;;;;=;;;#
=.............................   ..                            ;
=........................ ....    .                            =
=............. ........... .... .. ..                          =
=.......................... ....  ..          #                =
=..........................=. .     .. .     .;                =
=.........................@...  ..  ....     @                 =
=........................$......... . ...   $$                 =
=.......................$$$ ....  . .     -$$;                 =
=...................... $$....... .       $$$                  =
=......................$$$.....          $$$$  %.              =
=.....................#$@ ..... .       $@$$.  -@              =
=.....................$@$ .....         $%@@    @;             =
=....................$@%%......        @@@@$    ##             =
=....................;=#%. ...         #%@@;    ##=            =
=...................=;;=  . ..        ;;;%$     #=##           =
= .......... .......;;== ..           ;;;=@     #==#=          =
= ....... ... ..... ;;=#...          .;;;=-     .;=;##.        =
=.........  .......;;;=              ;;;;=.      ;;;#=         =
=..................;;=#              ;;;==       ;;;;=#        =
=.......   .......;;;=              .;;;#        ;;;=;%        =
=....... .........#;;#  .           =;;=#         ;;;==        =
=.........    .. .=;;@ ..-;#; .     ;;;#          -;;;;        =
=  .. ... ....... ;;#=----;-----;.  ;;=-        - -;;;;        =
=  .. ....  .    .==-----;-;;;;-;-;@;=@.        ; ;-;;;        =
=  .. ....   ..  .;;;;;;-;;;;;;;;;;;;@ .        ;  -;;;        =
=     ...       ;=;;;;;-;;;=####;;;;;=          ;; --;;        =
= .   . ..     @##=;;;;;;=@%---=$==;;;          -- --;=        ;
=     .       @--#%=;;;;#@;-..---$#=;;=         --.--;=        =
=            --...=%=;;=@-.......=%=;;;       ;.;---;;-        =
=            ;....-@=;;%$-.......-$#=;;       ;.;---;;.        ;
=           ;..  ..$%;;#@........-$%=;;@      -;-----;         =
=           @. . ..$%;;@@...$....-@%=;;#      ;------;         =
=           %.   ..$%;;@$........-$%=;;%    . ;------;         =
=           %.....;@=;;%$-.......-$#=;;-    = .-----==         =
=           %-...-$=;;;=@%......-$@#;;=     ;  ------#         =
=           %---#$%;;-;=%%$----;$%=;-;;    .=- -- ;-           =
=            $$$%#=;-;;;=%#@$@@%%=;--;      ;- --  =           =
=            #%##=;;---;;;=#@%%#==;;-;      --.--  #           ;
=            .=#==;-=;;-;;;==#==#=;;;       -----              =
=             =#==;;;;---;;;=======%       =-----              =
=              ;;;;;--=-;;;;======;.       #; --;              =
=               =;-----;;;;;;===@        @ ## .-;              =
=                 ==;;;;=;=%%#;;;@    % =. $=  =               =
=.                       .=#;;==;;.   -   @@   -               =
=. .                     %==;;;;;%%  ; @  @-                   =
=.                     .#-;;;;=;;;@  .-  ;$.                   =
=                      --;;;%-;;;;# $    $                     =
=                     $ --;;--;-;==%                           ;
= .                   . ;---;--;;=@. .               .         ;
=   .                   %;;--;;;;=                .            ;
=                       .%=;;;;;;                              ;
=                         %  .. =;; ..       .                 ;
=                  .......#.....%=.-;..........                ;
;               ......----@-----###;-.........                 ;
=             ........----------;----..........                ;
=              ..........-...-...--............                ;
=                ....=..--...=..;-%..-.-....                   ;
=                    ;. .-.=.-.; .#. @.@..                     ;
=                    ;%  .     =  %  % @                       ;
=                    ;  ..-    = .%. @ @                       ;
= .                  ;    . .. =  %. % @  .                    ;
=                    ;-  =     ;  %# % @                       ;
=                    ;   %  .  ;  %  %.#                       ;
=                    ;         -  %  % .                       ;
;                    ;    = . ..  #  %                         ;
=                    ;    - - =   #  %                         ;
=                    ;   . .% %   =                            ;
=                              . .   ..                        ;
=                            .#  =                             ;
;                           .##                                ;
=                         .. ;                                 ;
=                                                              ;
=                                                              ;
=                                                              ;
=                                                              ;
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

example2

PyAsciiArt.convert('example.jpeg', resize=128, contrast=1.5,
                   reverse=True, output='r_example_ascii.txt')
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$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$$$$$$$-%    @@$$$$$@%=   -%@$$$$$$$@#-#$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$#  $$; @@$$$$@= $$$  %$$$$%$$$%# @$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$   %$$$ %@$$$$%  $@$; #@$$-$$@@@% .- $$$$$$$$$$.
.$$$$$$$$$$$$$$$=  =$$= @@$$$$@  $$$  =@$@#.  =@@- ;= $$$$$$$$$.
.$$$$$$$$$$$$$$@#   .- -@$$$$$$- .#-  %@$   $$@@%# %%# $$$$$$$$.
.$$$$$$$$$$$$$- %=    ;@@$$$$$$@.    %@$$ #$$$$$@#.#%##$$$$$$$$.
.$$$$$$$$$$$$==##@%##@$$$$$$$$$$@###%@$$$ $$$$$$@@#. %  $$$$$$$.
.$$$$$$$$$$$=%##%@$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$@@# %   $$$$$$$.
.$$$$$$$$$$@%# =%$$$$$$$$$$$$$$$$$$$$$$=%$$$$$$$@@%    .$$$$$$$.
.$$$$$$$$$$$$% =@$$$$$$$$$$$$$$$$$$$$$$%$$$$$$$@$@%     $$$$$$$.
.$$$$$$$## .%% #%@$$$$$$$$$$$$$$$$$$-$-@$$$$$$$@@%= -   $$$$$$$.
.$$$$$$$$$#%@#.%%@$$$$$$$$$$$$$$$$$. .$ $$$$$$@@@#; =   $$$$$$$.
.$$$$$$$$ @%%% %%@$$$$$$$$$$$$$$$$$.-  @$$$$@$@%#=  =   $$$$$$$.
.$$$$$$$$$=### %%@$$$$$$$$  $$$$$$$ =@;%@@@@@@@==-.   .=$$$$$$$.
.$$$$$$$$$$    #%@$$$$$$$$$$$$$$$$$$##$%%@@@@%##       $$$$$$$$.
.$$$$$$$$$$$$  ;@@@$$$$$$$$$$$$$$$$$$ .;%@%%;##-       $$$$$$$$.
.$$$$$$$$$$$$$$ ##@@$$$$$$$$$$$$$$$$$$@  -.--.    .   $$$$$$$$$.
.$$$$$$$$$$$$$$@-%%$@@$$$$$$$$$$$$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; $ $$$$$$$$$$$$$$$$$$$$$$$-
.$$$$$$$$$$$$$$$$$$$$$$ $ $;$$$$ ;$$#$$@$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$ $.$-$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$ $;$ $$$$ $$$$.$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$  ;$ $$$$ $$$$@$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$; ;$;$$$$@$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$$  $%$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$.$#$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$-$.$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$  $$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.
.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$.

About

Convert image to character painting

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages