Convert image to character painting
You can use pip
to install this module:
pip install PyAsciiArt
Or download the source code and manual installation:
python setup.py install
There are two ways to use this module.
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.
from PyAsciiArt import PyAsciiArt
PyAsciiArt.convert('example.png', resize=128, contrast=1.5)
The specific usage can see function Annotations.
python -m PyAsciiArt example.png --resize 128
=========================================;=;;;;;;;;;;;;;;;=;;;#
=............................. .. ;
=........................ .... . =
=............. ........... .... .. .. =
=.......................... .... .. # =
=..........................=. . .. . .; =
=.........................@... .. .... @ =
=........................$......... . ... $$ =
=.......................$$$ .... . . -$$; =
=...................... $$....... . $$$ =
=......................$$$..... $$$$ %. =
=.....................#$@ ..... . $@$$. -@ =
=.....................$@$ ..... $%@@ @; =
=....................$@%%...... @@@@$ ## =
=....................;=#%. ... #%@@; ##= =
=...................=;;= . .. ;;;%$ #=## =
= .......... .......;;== .. ;;;=@ #==#= =
= ....... ... ..... ;;=#... .;;;=- .;=;##. =
=......... .......;;;= ;;;;=. ;;;#= =
=..................;;=# ;;;== ;;;;=# =
=....... .......;;;= .;;;# ;;;=;% =
=....... .........#;;# . =;;=# ;;;== =
=......... .. .=;;@ ..-;#; . ;;;# -;;;; =
= .. ... ....... ;;#=----;-----;. ;;=- - -;;;; =
= .. .... . .==-----;-;;;;-;-;@;=@. ; ;-;;; =
= .. .... .. .;;;;;;-;;;;;;;;;;;;@ . ; -;;; =
= ... ;=;;;;;-;;;=####;;;;;= ;; --;; =
= . . .. @##=;;;;;;=@%---=$==;;; -- --;= ;
= . @--#%=;;;;#@;-..---$#=;;= --.--;= =
= --...=%=;;=@-.......=%=;;; ;.;---;;- =
= ;....-@=;;%$-.......-$#=;; ;.;---;;. ;
= ;.. ..$%;;#@........-$%=;;@ -;-----; =
= @. . ..$%;;@@...$....-@%=;;# ;------; =
= %. ..$%;;@$........-$%=;;% . ;------; =
= %.....;@=;;%$-.......-$#=;;- = .-----== =
= %-...-$=;;;=@%......-$@#;;= ; ------# =
= %---#$%;;-;=%%$----;$%=;-;; .=- -- ;- =
= $$$%#=;-;;;=%#@$@@%%=;--; ;- -- = =
= #%##=;;---;;;=#@%%#==;;-; --.-- # ;
= .=#==;-=;;-;;;==#==#=;;; ----- =
= =#==;;;;---;;;=======% =----- =
= ;;;;;--=-;;;;======;. #; --; =
= =;-----;;;;;;===@ @ ## .-; =
= ==;;;;=;=%%#;;;@ % =. $= = =
=. .=#;;==;;. - @@ - =
=. . %==;;;;;%% ; @ @- =
=. .#-;;;;=;;;@ .- ;$. =
= --;;;%-;;;;# $ $ =
= $ --;;--;-;==% ;
= . . ;---;--;;=@. . . ;
= . %;;--;;;;= . ;
= .%=;;;;;; ;
= % .. =;; .. . ;
= .......#.....%=.-;.......... ;
; ......----@-----###;-......... ;
= ........----------;----.......... ;
= ..........-...-...--............ ;
= ....=..--...=..;-%..-.-.... ;
= ;. .-.=.-.; .#. @.@.. ;
= ;% . = % % @ ;
= ; ..- = .%. @ @ ;
= . ; . .. = %. % @ . ;
= ;- = ; %# % @ ;
= ; % . ; % %.# ;
= ; - % % . ;
; ; = . .. # % ;
= ; - - = # % ;
= ; . .% % = ;
= . . .. ;
= .# = ;
; .## ;
= .. ; ;
= ;
= ;
= ;
= ;
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
PyAsciiArt.convert('example.jpeg', resize=128, contrast=1.5,
reverse=True, output='r_example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