Space Cat, Prince Among Thieves

Damn Simple PHP ASCII Art Generator

So yesterday I was bored and asked my friend what I should do. She replied "I don't know, draw ASCII art or something!" and sitting there with the terminal open I kind of wondered what it would take to write one of those image to ASCII scripts.

20 minutes later I had the following PHP Shell Script! It works by simply sampling the saturation of every Xth pixel and mapping that saturation to a character from an array. There is no nearest-neighboring or anything like that, just straight up sampling.



And there you have it! A whopping 35 lines of code. There is a ton of tweaking you can do like changing the array of characters, or adjusting the $scale variable which is simply how wide of a sample it makes. Setting it to 1 for instance should sample every pixel on the Y and every other pixel on the X (so it scales propperly). To the right is a sample output of the script.

Do You Trust Me?

The script accepts local or remote image paths as the first argument. The following is a simple usage example you can use to get you started.

./ascii.php ""

It was a fun little project and I look forward to seeing if/what the internet comes up with for it. Fork me on Github, or post links in the comments! Happy hacking!

Comment by: A Name on

A Name's Gravatar Nice work man. A simple and clean little thing that is quite a catalyst for the old thought bubbles.

Comment by: cyan on

cyan's Gravatar A simple code but prospective. This website may be used a similar methods to generate ASCII Art

Comment by: cyan on

cyan's Gravatar sorry, i mean

Comment by: oguzhan on

oguzhan's Gravatar I think your not codder. You're artist! :) very funny 34 lines hah!

Comment by: Evan Toder on

Evan Toder's Gravatar How creative can you get with all these symbols?

Email address will never be publicly visible.

See my Tweet about comment formatting.