Jul 26, 2008

Asciilizer: Turn Your Image Into Text (php) - Turn your image into text

Free Web Hosting, No Ads > CONTRIBUTE > Computers

free web hosting

Asciilizer: Turn Your Image Into Text (php) - Turn your image into text

broflovski
Have you ever seen those replies in a guestbook or page where someone made a hand, face, or flower using nothing but zeros, dashes, and numbers?
I got a code that allows you to take an image from you computer, and turn it into a bunch of ones and ohs! The thing is that it's a PHP script.

Oh, and since it's text, if you were to say, upload a tiny image, like my avatar, it would take up the whole window.

CODE
<?
ob_start("ob_gzhandler"); // compression, a HUGE saving on this sort of thing.

function make($image){

   $size = getimagesize($image);
   if( !$size ) { die ("Error, file is not an image."); }
   $fsize= filesize($image);
   $type   = $size[2];
   $width  = $size[0];
   $height = $size[1];
   if($fsize>51200) {die("Image is too big. Max filesize is set to 50 Kbytes.");}
   if($width>500) {die("Image is too big. Max width  is set to 500 pixels.");}
   if($height>500){die("Image is too big. Max height is set to 500 pixels.");}

   // find imagetype and such
   switch ($type)
   {
       case 1:
           $im = imagecreatefromgif($image);
           break;
       case 2:
           $im = imagecreatefromjpeg($image);
           break;
       case 3:
           $im = imagecreatefrompng($image);
           break;
       default:
           $im = null;
           $extension="";
   }

   if(@$im){
       $imagearray = array();
       for($i=0; $i<$height; $i++){
           for($j=0; $j<$width; $j++){
               
               $rgb = ImageColorAt($im, $j, $i);
               $colorrgb = imagecolorsforindex($im,$rgb);
               $imagearray[($i*$width)+$j] = sprintf("%02X%02X%02X",$colorrgb['red'],$colorrgb['green'],$colorrgb['blue']);
           }
       }

       echo"<html><head><style>DIV { line-height:5px;letter-spacing:0px;}</style></head>";
       echo"<BODY BGCOLOR=\"#000000\"><BASEFONT SIZE=\"1\"><pre><div><font>";

       $k=0;

       for($i=0; $i<$height; $i++){
           for($j=0; $j<$width; $j++){
               
               $ch=rand(97,126);
               $ch2=chr($ch);
               if($k>0 && $imagearray[$k] == $imagearray[($k-1)]){
                   echo $ch2;
               }
               else{
                   echo "</font><FONT color=#" . $imagearray[$k] . ">" . $ch2 . "";
               }
               $k++;    
           }
           echo"\n";
       }
       echo"</font></div></pre></body></html>";
   }
   else{
       die ("Error, unsupported image type. Only gif, jpg and png are supported.");
   }
}

if ( $example=="tux") {  // User clicked the example link. Asciilize your example image.
   make("images/tux.jpg"); // this is my example image. Exchange for your own, or add more if you wish. Do NOT let the user choose a file from your drive. You don't want him asciilizing your password file :)
}

else if(@$uploadedimage){ // A file has been uploaded, so make the ascii-code    
   if ( is_uploaded_file( $_FILES['uploadedimage']['tmp_name'] )) {
       make($_FILES['uploadedimage']['tmp_name']);
   }
}
else{// A file has NOT been uploaded, so write upload-form html code
   ?>
       <html>
       <head>
           <title> Asciilizer </title>
       </head>

       <body>
           <br />Upload the image you want to asciilize. <br />Supported image formats are: gif, jpeg or png. Max filesize is set to 50 Kb and allowed measurements are H&lt;500 px & W&lt;500 px.
           <br />Please, there is no point in trying 2mb screengrabs and such, as it will just fail anyway.
           <br />Keep in mind that the ascii version will be 6 times wider and taller = 36 times the area.
           <br />As such, large images might stall or even crash your browser.
           <br />The optimal image to asciilize, is one with few colors, sharp transitions, around 200x200 pixels, and large areas of the same color.            <br />
           <br />Upload it to any php-enabled webserver if you want to play with it. PS: If you wanted to enable larger images, you might need to re-configure your webserver with a larger POST-max-filesize, longer execution-timeout-limit.<br /><br />
        <form enctype="multipart/form-data" action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
           <input type="hidden" name="MAX_FILE_SIZE" value="51200">
           <input type="file" name="uploadedimage"    size="40">
           <input type="submit" value="Asciilize it!">
       </form>

       </body>
       </html>
   <?
}
?>

 

 

 


Reply

RGPHNX
Hi broflovski,
cool script. How about a short tut (tutorial) on how to use it. For those of us who aren't so PHP savy.
RGPHNX

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. turning picture files - 3.66 hr back. (1)
  2. how to turn a picture into code - 4.52 hr back. (1)
  3. turn images to codes - 4.90 hr back. (1)
  4. how to turn text into jpg - 18.42 hr back. (1)
  5. turn images into codes - 19.56 hr back. (1)
  6. free php code to upload text and image together - 22.40 hr back. (1)
  7. turning jpegs into html? - 24.32 hr back. (1)
  8. turn picture into php - 24.88 hr back. (1)
  9. "picture to html code" - 28.68 hr back. (1)
  10. how to turn a jpeg into html - 33.54 hr back. (1)
  11. turn a jpeg pic into html code - 37.24 hr back. (1)
  12. turn .html into .php - 37.40 hr back. (1)
  13. how do i turn a file into php - 46.42 hr back. (1)
  14. turn image name - 58.28 hr back. (1)
Similar Topics

Keywords : asciilizer, turn, image, text, php, turn, image, text

  1. Random Images
    how to make a random image? (10)
  2. Need Html Help
    help with image maps... (4)
    Ok, I set up an image map for the sidebar on my site, www.rlclan.trap17.com . what i was wondering
    was, how the crap do i remove that blue border? i tried putting border="0" in the image tag, does
    it matter where it is placed? (before or after the usemap="#navagation")....

    1. Looking for asciilizer, turn, image, text, php, turn, image, text

Searching Video's for asciilizer, turn, image, text, php, turn, image, text
advertisement



Asciilizer: Turn Your Image Into Text (php) - Turn your image into text



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE