+ Reply to Thread
Results 1 to 2 of 2

Thread: IMG to ASCII converter

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    13

    IMG to ASCII converter

    Is there anyway i could convert an image into ASCII code ?
    Last edited by lostcode; 11-12-2012 at 02:31 AM.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    41
    we will Take a JPG image, and convert it to ASCII code

    Code:
    <html>   
    <head>   
    <title>Ascii</title>   
    <style>   
    body{   
        line-height:1px;   
        font-size:1px;   
    }   
    </style>   
    </head>   
    <body>   
    <?php   
    function getext($filename) {   
        $pos = strrpos($filename,'.');   
        $str = substr($filename, $pos);   
        return $str;   
    }   
    $image = 'pic.jpg';  
    $ext = getext($image);   
    if($ext == ".jpg"){   
        $img = ImageCreateFromJpeg($image);   
    }   
    else{   
        echo'Wrong File Type';   
    }   
    $width = imagesx($img);   
    $height = imagesy($img);   
    
    for($h=0;$h<$height;$h++){   
        for($w=0;$w<=$width;$w++){   
            $rgb = ImageColorAt($img, $w, $h);   
            $r = ($rgb >> 16) & 0xFF;   
            $g = ($rgb >> 8) & 0xFF;   
            $b = $rgb & 0xFF;   
            if($w == $width){   
                echo '<br>';   
            }else{   
               echo '<span style="color:rgb('.$r.','.$g.','.$b.');">#</span>';  
            }   
        }   
    }   
    ?> 
    </body> 
    </html>
    Hope that tutorial helps you.

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts