Dark Bit Factory & Gravity

GENERAL => Projects => Topic started by: combatking0 on February 05, 2013

Title: [Image Processing] - ASCII-inator
Post by: combatking0 on February 05, 2013
Just for fun, I thought I'd try to build an image-to-ASCII-art converter in JS.

To use it, you'll need to unzip the archive, and place a GIF, JPG or PNG file in the same directory as the HTM file.
Next open the program under Firefox or IE9 and type the complete file-name of the image into the form.
Then press the Generate button. If the file-name is correct, the image should be converted into ASCII art.

It's only been successfully tested under Firefox and IE9. Chrome doesn't work due to a false-positive in its default security settings.

(edit) I have improved the code for better contrast handling, but only slightly.

Here's an output sample:
Code: [Select]
                               ¤xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx•                                     
                               ¤xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx•                                     
                               ¤xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx•                                     
                         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx·                 
                         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx·                 
                         xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx·                 
                         NNNNNNNNNNNNNNNNNNX¤¤¤¤¤¤¤¤¤¤¤¤NMMMMMX¤¤¤¤¤•············                   
                         MMMMMMMMMMMMMMMMMMN••••••••••••NMMMMMX••••••                               
                         MMMMMMMMMMMMMMMMMMN••••••••••••NMMMMMX••••••                               
                  ·xxxxxxxxxxxxNMMMMMXxxxxxx••••••••••••NMMMMMX••••••............·                 
                  .MMMMMM••••••NMMMMMX••••••••••••••••••NMMMMMX••••••••••••••••••·                 
                  .MMMMMM••••••NMMMMMX••••••••••••••••••NMMMMMX••••••••••••••••••·                 
                  .MMMMMM••••••NMMMMMNxxxxxx••••••••••••xXXXXXXXXXXXx••••••••••••......·           
                  .MMMMMM••••••NMMMMMMMMMMMN••••••••••••••••••XMMMMMN••••••••••••••••••.           
                  .MMMMMM••••••NMMMMMMMMMMMN••••••••••••••••••XMMMMMN••••••••••••••••••.           
                  ·xxxxxxxxxxxxXXXXXXXXXXXXx••••••••••••xxxxxxNMMMMMMxxxxxxxxxxxx•.....·           
                         MMMMMM¤••••••••••••••••••••••••NMMMMMMMMMMMMMMMMMMMMMMMM.                 
                         MMMMMM¤••••••••••••••••••••••••NMMMMMMMMMMMMMMMMMMMMMMMM.                 
                         XXXXXX¤•••••¤•••••¤••••••••••••XNNNNNNNNNNNNXXXXXXXXXXXX.                 
                               ••••••••••••••••••••••••••••••••••••••                               
                               ••••••••••••••••••••••••••••••••••••••                               
                         ·     •¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤•     ·                         
                         xxxxxxxxxxxxXXXXXXXxxxxxxxxxxxxXXXXXXXxxxxxxxxxxxx                         
                         xxxxxxxxxxxxXXXXXXXxxxxxxxxxxxxXXXXXXXxxxxxxxxxxxx                         
                         xxxxxxxxxxxxXXXXXXXxxxxxxxxxxxxXXXXXXXxxxxxxxxxxxx                         
                  ·xxxxxxxxxxxxxxxxxxXXXXXXXxxxxxxxxxxxxXXXXXXXxxxxxxxxxxxxxxxxxx·                 
                  ·xxxxxxxxxxxxxxxxxxXXXXXXXxxxxxxxxxxxxXXXXXXXxxxxxxxxxxxxxxxxxx·                 
                  ·xxxxxxxxxxxxxxxxxxXXXXXXXxxxxxxxxxxxxXXXXXXXxxxxxxxxxxxxxxxxxx·                 
            .xxxxxxxxxxxxxxxxxxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxx.           
            •xxxxxxxxxxxxxxxxxxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxx•           
            •xxxxxxxxxxxxxxxxxxxxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxxxxxxxxxxxxxxxxxxxx•           
            .¤¤¤¤¤¤¤¤¤¤¤¤xxxxxxXXXXXXx¤¤¤¤¤¤XXXXXXXXXXXX¤¤¤¤¤¤xXXXXXXxxxxxx¤¤¤¤¤¤¤¤¤¤¤¤.           
            .••••••••••••xxxxxxXXXXXX¤•••••¤XXXXXXXXXXXX¤•••••¤XXXXXXxxxxxx••••••••••••.           
            .••••••••••••xxxxxxXXXXXX¤•••••¤XXXXXXXXXXXX¤•••••¤XXXXXXxxxxxx••••••••••••.           
            .•••••¤••••••¤¤¤¤¤¤xXXXXXxxxxxxxXXXXXXXXXXXXxxxxxxxXXXXXx¤¤¤¤¤¤••••••¤•••••.           
            .••••••••••••••••••xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx••••••••••••••••••.           
            .••••••••••••••••••xXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXx••••••••••••••••••.           
            .•••••¤••••••xxxxxxXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXxxxxxx••••••¤•••••.           
            .••••••••••••XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX••••••••••••.           
            .••••••••••••XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX••••••••••••.           
            ·............XXXXXXXXXXXXXXXXXXx¤¤¤¤¤¤¤¤¤¤¤¤xXXXXXXXXXXXXXXXXXX............·           
                         XXXXXXXXXXXXXXXXXX¤            ¤XXXXXXXXXXXXXXXXXX                         
                         XXXXXXXXXXXXXXXXXX¤            ¤XXXXXXXXXXXXXXXXXX                         
                   ......XXXXXXXXXXXXx¤¤¤¤¤•            •¤¤¤¤¤xXXXXXXXXXXXX......                   
                  .MMMMMMMMMMMMMMMMMM¤                        ¤MMMMMMMMMMMMMMMMMM.                 
                  .MMMMMMMMMMMMMMMMMM¤                        ¤MMMMMMMMMMMMMMMMMM.                 
            ······•MMMMMMMMMMMMMMMMMM¤                        ¤MMMMMMMMMMMMMMMMMM•······           
            ¤MMMMMMMMMMMMMMMMMMMMMMMM¤                        ¤MMMMMMMMMMMMMMMMMMMMMMMM¤           
            ¤MMMMMMMMMMMMMMMMMMMMMMMM¤                        ¤MMMMMMMMMMMMMMMMMMMMMMMM¤           
            ¤MMMMMMMMMMMMMMMMMMMMMMMM¤                        ¤MMMMMMMMMMMMMMMMMMMMMMMM¤           

I may need to make some adjustments.

(edit) I've updated again - I should really do more testing before I release :)
Charset 10 is now the default, non-existent files are handled better, and you can now choose between 3 scaling options. Also, the courier font aspect ratio is better catered for.
Title: Re: [Image Processing] - ASCII-inator
Post by: Kirl on February 06, 2013
Awesome, works really well! Time for some moving pictures!  :cheers:
Title: Re: [Image Processing] - ASCII-inator
Post by: combatking0 on February 06, 2013
Thanks Kirl, I've been fine tuning it.

A moving demo is definitely on the cards.
Title: Re: [Image Processing] - ASCII-inator
Post by: Shockwave on February 23, 2013
Phineas and Ferb inspired name? :)
Title: Re: [Image Processing] - ASCII-inator
Post by: combatking0 on February 23, 2013
Yes, my son loves that show. I quite enjoy it too.
Title: Re: [Image Processing] - ASCII-inator
Post by: jace_stknights on February 28, 2013
Thanx mate!