$img2Ascii = new Img2Ascii();
$img2Ascii->setImageFile(__DIR__ . "/example.jpg");
$img2Ascii->write();
$img2Ascii->get();
$outputStream = fopen("php://output", "a+");
$img2Ascii->toStream($outputStream);
$img2Ascii->callback(
function (string $char)
{
echo htmlentities($char);
},
function ()
{
echo "<br />";
});
$img2Ascii->setChars('@#%$?*+";:,. ');
When you don't want each pixel to be translated into a character, but want to collect the brightness of a rectangle
(so-called "block"), set it with setBlockSize()
. This reduces the width and height of the resulting ascii image.
$img2Ascii->setBlockSize(4);
$img2Ascii->setChars('█▓▒░ ', true);
// or
$img2Ascii->setChars('█▓▒░ ');
$img2Ascii->multibyte();
http://localhost/?s=0&img=spongebob
http://localhost/?s=1&img=spongebob
http://localhost/?s=2&img=spongebob
http://localhost/?s=3&img=spongebob
Example result
.........,...,:,...,,.............................
........+"+""""++"""++";;++";"";:;;,..............
.......";;:::::::::::::::::::::::::+..............
......,";;::;++":::::::::::::::::"+;:.............
.....:";;"::"+++;":?";*::;+:?;:;;++":.............
....,+;++"::;++;;%"?+?+::;$"$"+?:;:",.............
....;;"?*;":::::;+, ."":":. ,*;:::"..............
...:";+?*;;::"":" ;". ;:::"..........:...
...+;;+?+;;;:::". .;:.; .;. ."::;:.......,*+:..
..,";;;*;;;;:::" .+??::,*?*. ;::;;.......*;+...
...+;;;;;;;":::" ,*@@;:;$@?: ;::":......";+....
...:";;;;;;":::". .+??,;:?$*. "::+.....:;?*"....
....";;;+;;":::;";:..:,;; :", ,;+::"....,*:***:...
....;;;+?";":::;:::;..;;;: .:;;:;+:"....""+?:;;...
....:";*?;;;::::;+;:"+;::"+":::;?;:"....:";+++....
.....;;"+;";:::::*;:::::::""+***:::+.....";:""....
......;;;+?+;::::*%":::::::"*;:::::+.....;;+;.....
......;;;*?+;::::*$%$?****++*?;::::;.....++.......
......";;+?+"::::*$$$%: +%. +::;";::....:"+.......
......,;;"*;"::::*$$$%":*%;:+::+++:;....+",.......
.......:;;;;"::::*$$$$%%%%+::::++":;...:"+........
.......:";;+"::::+%%%$$$$#;::::;;:;*;;.*+:........
........+"+?;;:+:;*:"?+?%%:::::;;:"."+*;*.........
........;:*";;:;;:"*";::$$::::;++:; +*++..........
.......;. ;;;;:++;::+???*;:::::";:; ,;............
......." ;;;;:++:::::::::::::::::+++.............
......." ;";;:;;:::;;::::;;:::;;":...............
.......;""+,,;"::;*;,:"**?;:+;:,:*................
........"+",,:, .;;;,"$::;: +................
........""%#$?*""""""""???+""""++*................
........;"%##$?%###*%#@$?#@@$#@@%*................
........:"%$$$?????*???%?$??*???*+................
........,"%$$$?********?$********+................
........":"?$#$$$$$$$$$$$$%%%$$$$;................
........+::";$$$$$%:,,,;$?**?;....................
........+:"+,?$???*.....:??":.....................
........*"*;..+?+,......."+.......................
........**+..."":........+".......................
.........;:..."+,........+".......................
.............."*,........+".......................
.............."".........*;.......................
.............."".........";.......................
..............*:,.......+$?.......................
.............*@##,,.....@@@%@@:...................
.............+@@@@@*....%@@@?@*...................
.............;@@@@##...."%$@@@:...................
..............:;%@@*.......,",....................
.................;;...............................
..................................................
There is no such thing. Use it as you'd like, change it, or rewrite it completely. And feel free to drop me a mail at [email protected]