<?
/// Conversion d'une image jpeg en html avec des tableaux
/// par Pierre-Francois Leon
/// leon@sic.univ-poitiers.fr - http://www.chezpifou.com/

$argc=$_SERVER['argc'];
$argv=$_SERVER['argv']; 

if (
$argc == 2) {
  
$filename $argv[1];
} else if (isset(
$_GET['file'])){
  
$filename $_GET['file'];
} else {
  die(
"filename error !\n");
}

if (
$filename=="showsrc") {
  
$filename __FILE__;
  
highlight_file($filename);
  
  exit(
0);
}

if (!
is_callable('imagecreatefromjpeg')) {
  die(
"gd not installed !\n");
}
?>
<html>
<head>
<style type="text/css">
table {
  border-spacing:0px;
  border:0px;
  border-collapse:collapse;
}

tr {
  height:1px;
  padding:0px;
}

td {
  width:1px;
  padding:0px;
}
</style>
</head>
<body>

<?
echo convertJped2Html($filename);
?>

</body>
</html>

<?
function convertJped2Html($filename) {
  
$img = @imagecreatefromjpeg($filename);

  if (!
$img) {
    die(
"can't open file\n");
  }
  
  
$width imagesx($img);
  
$height imagesy($img);
  
  
$res '<table>';
  
  for(
$y 0$y $height$y++) {
    
$res .= '<tr>';
    for(
$x 0$x $width$x++){
      
$color imagecolorat($img$x$y);
      
$res .= '<td bgcolor="'.str_pad(dechex($color),6,"0",STR_PAD_LEFT).'" />';
    }
    
//    $res .= "</tr>\n"; // pour gagner de la place on vire le /tr
    
$res .= "\n";
  }
  
$res .= '</table>';
  
  return 
$res;
}

?>