DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

JPG Image, And Convert

11.22.2011
| 1915 views |
  • submit to reddit
        <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 = 'image.jpg'; 
$ext = getext($image);  
if($ext == ".jpg"){  
    $img = ImageCreateFromJpeg($image);  
}  
else{  
    echo'Wrong File Type';  
}  <a href="http://www.twizap.com/game/shadow-of-the-warrior.html">Shadow of the Warrior</a>

$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>