Function img2html » Image to HTML Converter
415 690 CHR
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
function hexcolor($c) {
$r = ($c >> 16) & 0xFF;
$g = ($c >> 8) & 0xFF;
$b = $c & 0xFF;
return str_pad(dechex($r), 2, '0', STR_PAD_LEFT).
str_pad(dechex($g), 2, '0', STR_PAD_LEFT).str_pad(dechex($b), 2, '0', STR_PAD_LEFT);
}
function imagize($img) {
$image = imagecreatefrompng($img);
$width = imagesx($image);
$height = imagesy($image);
$table = '<table border="0" cellpadding="0" cellspacing="0"><tr height="0">';
for($horizontal=0; $horizontal<$width; $horizontal++) {
$table .= '<td width="1"></td>';
}
$table .= '</tr>'; //fermer les balises sinon ca fait planter le nav.. c'est pas que pour se la péter le valid W3C
for($vertical=0; $vertical<$height; $vertical++) {
$table .= '<tr height="1">';
for($horizontal=0; $horizontal<$width; $horizontal++) {
$color = imagecolorat($image,$horizontal,$vertical);
for($colspan=0; $colspan<($width-$horizontal); $colspan++) {
if ($color != imagecolorat($image,($horizontal+$colspan),$vertical)) {
break;
}
}
$horizontal=$colspan+$horizontal-1;
$table .= '<td';
($colspan)? $table .= ' colspan='.$colspan.' ':'';
$table .= 'bgcolor='.hexcolor($color).'></td>';
}
$table .= '</tr>';
}
$table .= '</table>';
$table .= '<br /><br />'.number_format(strlen ($table), 0, ',', ' ').' CHR';
return $table;
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<?=imagize('logo.png') ?>
</body>
</html>