<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr" id="facebook" class=" no_js">
<head>
<style type="text/css">
body { font-family: sans-serif; font-size: 85%; }
pre { font-size: .6em; }
</style>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
</head>
Image:<br/>
<FORM method="POST" action="index.php" ENCTYPE="multipart/form-data"> 
<INPUT type=file name="image">
<br/>
Colonnes: &nbsp;<br/>
<input type="text" name="cols" value="80">
<INPUT type="submit" value="Envoyer">
</FORM>


<?php
//---------------------------------------------------------------------------------------
if ($_FILES['image']['error']) 
    {
          switch (
$_FILES['image']['error'])
            {
                   case 
1// UPLOAD_ERR_INI_SIZE
                   
echo"Le fichier dépasse la limite autorisée par le serveur (fichier php.ini) !";exit(0);
                   break;
                   case 
2// UPLOAD_ERR_FORM_SIZE
                   
echo "Le fichier dépasse la limite autorisée dans le formulaire HTML !";exit(0);
                   break;
                   case 
3// UPLOAD_ERR_PARTIAL
                   
echo "L'envoi du fichier a été interrompu pendant le transfert !";exit(0);
                   break;
                   case 
4// UPLOAD_ERR_NO_FILE
                   
echo "Le fichier que vous avez envoyé a une taille nulle !";exit(0);
                   break;
                  }
    }
else 
    {
$chemin_destination './';
move_uploaded_file($_FILES['image']['tmp_name'], $chemin_destination.$_FILES['image']['name']);

print_r($_FILES['image']);
echo 
"<hr>";
$size = @getimagesize($_FILES['image']['name']);
print_r($size);


if (!
$size){echo "pas une image";exit(0);}

echo 
"<hr/>";
$haut=$size["0"];
$larg=$size["1"];

if(!isset(
$_POST['cols']))
{echo 
"pas de valeur de colonne => defaut = 80";$cols=80;}else{$cols=$_POST['cols'];}
$bloc=(int)($larg/$cols);

}


//-----------------------------------------------------------------------------------
echo "<pre>";
$rows=(int)$haut/$bloc;
// et on attaque
$im imagecreatefromjpeg($_FILES['image']['name']);
for(
$j=0;$j<$cols;$j++)
    {for(
$i=0;$i<$rows;$i++)
    
        {
        
$sign=analyse_bloc($im,$bloc,$i,$j);

        
//echo $asc[(int)$sign*$nb_char/256] ;

        
}
echo 
"\n";

    }
function 
analyse_bloc($im,$bloc,$a,$z)
    {
$r=$g=$b=$val=0;
$bloc=(int)$bloc;
$debuth=1+$bloc*$a-$bloc;
$finh=$bloc*$a;
$debutv=1+$bloc*$z-$bloc;
$finv=$bloc*$z;
    for(
$i=$debuth;$i<$finh;$i++);
        {
        for(
$j=$debutv;$j<$finv;$j++);
            {
            
$rgb = @imagecolorat($im,$i,$j);
            
$r = ($rgb >> 16) & 0xFF;
            
$g = ($rgb >> 8) & 0xFF;
            
$b $rgb 0xFF;
                 
$val+=($r+$g+$b)/3;
            }
        }
//echo (int)$val.".";
echo "<span style=\"color:rgb($r,$g,$b);background: rgb($r,$g,$b)\">██</span>" ;
    return (int)(
$val);
    }
?>
</pre>