View Full Version : LEIA ASCII Logo!


iTom
11-24-2006, 08:38 PM
I decided to write an ASCII art PHP and GD script. It creates a composition out of letters and symbols you find on your everyday keyboard. It looks at each pixel in a PNG image, pokes it, prods it and then gets the colors for the position. It then calculates an average color value composed of red, green and blue. It then divides that number by 3 and gets a number from 0-85. It chooses a symbol from this. Quite complex for 30 lines (or so) of code. :P



++++++++V*<<:+++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++
+++++++?$6&B8;+++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++=(*++++++++++++++++
+++++++%8++*MB*++++++++9999;++++++++++++++++++++++ +++++++++++++++++++++=)))(((+++++()))(=+++
+++++++%P''~^V++++++++6#$$@$*+++++++++++++++++++++ +++*;%%%%>*+++++++++=)((((()(++(()(((((=++
+++++++%P ~V#*++++++*%P-_*%v+++*++++++++++++*+++++*8#BAXX6A@;++++++++((((( ((()(+((((((((=++
+++++++%P ~V8*++++++*&* j?^:>V8??v;+++*<vvv%vv<*:8#?=)__-)?%<+++++++((((((((((()((((((((++
+++++++%P ~V?+++++++*&> (9##@??^?B#^<*?#8?^?P##X9#V- \?&<+++++=((((((((()))((((((((=+
+++++++%P ~V#*+++++++&&+)^##V*\i-\+V%$?Bv(\~!|*v9#?~ ~_ /#?+++++=(((((((((())((((((((=+
+++++++%P ~V?+++++++*V#%9##V- ~*@&*_ '~+9X>~~+>v+_ ~^&>(=++=((((((((((((((((((()++
+++++++%P ~V8*++++++*?vvv?V- ~v?_ _>##^^8##A- '*#V)((++((((((((((((((((((((++
+++++++%P ~V#*++++++?@\__*+ /??>~ (9* |^?+-_*B########+''+#V(())+(((((((((((((((((((=++
+++++++%P ~VV+++++++M#i *+ (B%%VP$%+ (P%%XV@###B*\-~-_ -#V((((+=((((((((((((((((()+++
+++++++%P ~V#*++++++M#- _<*' ~/+V8@%*' ~-*?8###6j -#V(((()=((((((((((((((()(=+++
+++++++%P ~V6*++++++M# _<?/' _/?#6)~ ~)?#8/ '_' -#V(((())((((((((((((((((=++++
+++++++%P ~V?*++++++9# _<#?*i__ !?#X*/~' \?*~ '\*:*_ -#V((((((((((((((((((((((+++++
+++++++%P ~V#?^^^^^^%# _<###?v>+\_ +###9V**j +- j?###)' ~?X*(((((((((((((((((((=++++++
+++++++%P ~*A^VVVVVVVV _<##^V##&?+~ ~#8VM###^! /\' -^###( _*#X*(((((((((((((((((=+++++++
+++++++%P '_-~~~~~~~~* _<?)~~V##?\ _P-~|?##Aj /*_ '\>>*_ -*?6+(((((((((((((((=++++++++
+++++++%P * _<^~ _+*-' |P~ _*(_' *&) ~~~ ~:#*((((((((((((((=+++++++++
+++++++%M~~~~~_~__~__~*~~~>#*_ _%#V' '/?##;_~ ~_~'~v#*((((((((())()(++++++++++
+++++++M&<<<<<&>V6<?^<%<<<?##*~~ '_-9@A9+~~ _~(?&X9@&*----:%;)+?8+(((((((((+=((+++++++++++
+++++++*?????PPPPPPPPP????P?&#V*))+>A#?:6#^*()*^#B<+*?X##P9##M####*((((((()(++++++++++++++++
++++++++*******************+>?@####X?^*+;?8####%?>+++**^^???^*^^^V+(((((()(+++++++++++++++++
++++++++++++++++++++++++++++++>vvvv*++++++*vvvv<+++++++++***+++++=)((((()+**++++++++++++++++
++++++++???????++++++++++++++^?^*+++++++**++++++++ ++++++++***^*V++()((((*?MM**?????*++++++++
+++++++P#######P++++++++++++?@#@?****++;AAV+++++++ +++++++VAA8@B$^++))((*B#^BA8#####A*+++++++
+++++++%M_____M%**+++++++++*Mv~<@%&&%%;%P^$v++++*****+++V@$%#*+@?*++)((V@+~*%#^_(\+&*+++++++
+++++++%P ~~~~X#&#?*;;;%VM?^9>~;8V++^@#M--?#V;<V##%B@@;+^#('?\_v%?*+(/-^^- (%#V \-+B*+++++++
+++++++%P =&X%#P*M##XM@X???A#>~*='__~^#B*+^P$6##B^*=vXB*^#*++-_=v#;+++v#V~_'?#V \-+B*+++++++
+++++++%P i*(V$v_)?P(|A+~~~+^;~*:)><~)$%??*\*)>?;_~_'+B*^#6?- '_*#;+++^&+_+_*#V \-+B*+++++++
+++++++%P ~~~+B$*~|/~=&i~(=_-*~<&V<<~_%M\(j _~+!~|*(>B*V9++<~_*?X*++*#^~+^~\#V \-+B*+++++++
+++++++%P \VV?$#&* -P#i~VA*_+~*>\__' %? -j_*V'/\~~(*%$^V^-=B\_v#8;++PB+ /*_~#V \-+B*+++++++
+++++++%P =#####B+ -P#i~V#>_+~*_~==_ %? -j-?# !V=\~_*#XV^-=B\-??#A:*#P- ~_ 'VV \-+B*+++++++
+++++++%P =##V<%*~-(_/Bi~V?\ +~+ -^Bj >? -j/9#'+?V8M~_#XV^-=B*_;(+X<*#^'-+++'iV \-+B*+++++++
+++++++%P '~~~~*'-^$*_/i _~'=*~*+'~~''_+'ij(6;'(+~+(~_#XV^-+B*'''*@<B8--^%&$/~V \-(B*+++++++
+++++++%8)\++++:\^%%#*Bi'~-+9Viv6*|-);i:+*=*AviV?!__-<@?V?**&%)-(?&<%8-*#^*A>!*/+((A*+++++++
+++++++?####A%9##%Vv&6$i~V##8$#$6#######%A##6@###Pvv&@?*>BA%9####B<+^###&v*?@######9*+++++++
++++++++^^^^:v*^^v++>^%)~V8^*V^V*^^^^^^^v;^^*V^^^?????*++>:v*^^^^<+++^??v++*^^^^^^^*++++++++
+++++++++++++++++++++v%*~V?++++++++++++++++++++++* +++*++++++++++++++++**++++++++++++++++++++
+++++++++++++++++++++*&?V6?++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++
++++++++++++++++++++++>##X*++++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++
+++++++++++++++++++++++**+++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++++



I hope you like it. Give me some comments, or ask for the source code (released under Open Source GNU License), because it wouldn't fit on here. Stupid 5000 character limit - it doesn't allow both. :(

Arwen
11-24-2006, 08:44 PM
Awesome! :D

iTom
11-24-2006, 08:51 PM
Ok, here's the source code for you PHP coders! I'm sure someone could convert this to Perl, maybe even C++! Enjoy, released under free license, give credit when used, yadda yadda...


<div style="width: 100%; overflow: scroll; ">
<?
// Generates ASCII art from an image

function ascii_art($gd_res, $bw = false, $bwcolor = '#000000') {
// get the array of symbols
$ranges = array("#", "@", "$", "%", "%", "&amp;", "B", "A", "8", "6", "9", "X", "M", "P", "?", "?", "?", "?", "?", "^", "^", "^", "^", "^", "V", "V", "V", "v", "v", "v", "&gt;", "&lt;", "&gt;", "&lt;", ";", ";", ":", "*", "*", "*", "*", "*", "*", "*", "*", "*", "+", "+", "+", "+", "+", "+", "=", "(", ")", "(", ")", "(", "/", "/", "|", "\\", "\\", "!", "j", "i", "-", "-", "-", "-", "-", "~", "~", "~", "~", "_", "_", "_", "_", "_", '~', '~', "'", "'", "&nbsp;", "&nbsp;", "&nbsp;", "&nbsp;");

// iterate through each pixel in the image
for($pw = 0; $pw < imagesx($gd_res); $pw++) {
for($ph = 0; $ph < imagesy($gd_res); $ph++) {
// get the general color values
$rgb = imagecolorat($gd_res, $ph, $pw);

// calculate the colors
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;

// add the general values all together and calculate an average
$avgcl = round((($r + $g + $b) / 3) / 3, 0);

// calculate the color
$c = sprintf('#%06x', $rgb);

// print the respective symbol
echo("<span style=\"font-size: 8pt; font-family: Terminal; \">" . $ranges[$avgcl] . "</span>");
}

// print line break
print("<br>");
}
}
$res = imagecreatefrompng('FILENAME FOR THE INPUT');
echo ascii_art($res, false);
?>
</div>


Enjoy! :)

Arwen
11-24-2006, 09:29 PM
Haha, I didn't notice "it all"! :lol: Had to edit the post. :D

iGeek
11-24-2006, 09:40 PM
Cool!

Marta
11-24-2006, 09:55 PM
That's pretty neat!!! :D

Patrick
11-24-2006, 11:58 PM
That's awesome. I will try to convert it to C++. :)

iTom
11-25-2006, 12:05 AM
Thanks! :) You just need the GD library.

Idiotic Creation
11-25-2006, 01:26 AM
Good work Tom. I might try to convert it to C++ later too, but I'm still learning and also working on a different project.

Owlie42
11-25-2006, 05:57 AM
That is amazing.

iTom
11-25-2006, 08:38 AM
Thanks everyone! :)

Magln Meow
11-26-2006, 11:19 PM
*steps a couple feet back*
Wow, that's incredible! :D Nice work.

iGeek
11-27-2006, 03:06 AM
I know Patrick is porting it to C++, I'll try for C, much simpler!

SUPER RP06
11-27-2006, 09:41 PM
//stands back 2-3 metres

Wicked cool!!!!!!

iTom
12-02-2006, 11:05 PM
Thanks!