Jump to content
xisto Community
broflovski

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

What do you think of the script?  

4 members have voted

You do not have permission to vote in this poll, or see the poll results. Please sign in or register to vote in this poll.

Recommended Posts

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.

<?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<500 px & W<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>    <?}?>

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.