Filehost.ro - gazduire fisiere
H4cky0u Forum
Tutoriale de toate tipurile
Nou pe simpatie:
pisi_dulce 25 ani
Femeie
25 ani
Maramures
cauta Barbat
28 - 57 ani
H4cky0u ForumReguliInregistrareLoginPozeNu sunteti logat. Lista Forumurilor Pe Tematici
H4cky0u Forum / PHP /

[PHP] JPG to ASCII

Pagini: 1 Moderat de PaiN
#1
GaMa
Administrator
Postari: 205


Code:

<html>
<head>
<title>Ascii</title>
<style>
body{
    line-height:7px;
    font-size:10px;
}
</style>
</head>
<body>
<?php
function getext($filename) {
    $pos = strrpos($filename,'.');
    $str = substr($filename, $pos);
    return $str;
}
if(!isset($_POST['submit'])){
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
    JPG img URL: <input type="text" name="image"><br>
    <input type="submit" name="submit" value="Create">
</form>
<?php
}else{
    $image = $_POST['image'];
    $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;
            echo '<span style="color:rgb('.$r.','.$g.','.$b.');">#</span>';
            if($w >= $width){
                echo '<br>';
            }
        }
    }
}
?> 
</body>
</html>



 
   
Pagini: 1  
Mergi la