<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Tests du schéma data</title>
</head>
<body>
<?php
if ($_REQUEST['show'] == 'source') {
echo "<p>\n";
highlight_file('index2.php');
echo "</p>\n";
echo "</body>\n";
echo "</html>\n";
exit;
}
// On crée une image (disque noir sur fond rouge)
$im = imagecreatetruecolor(20, 20);
$red = imagecolorallocate($im, 255, 0, 0);
$black = imagecolorallocate($im, 0, 0, 0);
imagefill($im, 0, 0, $red);
imagefilledellipse($im, 10, 10, 10, 10, $black);
// On bufferise la sortie pour récupérer l'image
// dans une chaîne au lieu de l'envoyer dans un
// fichier ou vers la sortie standard
ob_start();
imagejpeg($im);
$jpeg_bin = ob_get_contents();
ob_end_clean();
// Même chose en PNG
ob_start();
imagepng($im);
$png_bin = ob_get_contents();
ob_end_clean();
// Destruction de l'image
imagedestroy($im);
// Maintenant on encode l'image en base64
$jpeg_b64 = base64_encode($jpeg_bin);
$png_b64 = base64_encode($png_bin);
// Ceci pour améliorer la présentation
$jpeg_chunks = "\n\t" . chunk_split($jpeg_b64, 60, "\n\t");
$png_chunks = "\n\t" . chunk_split($png_b64, 60, "\n\t");
?>
<p>
Image JPEG
<img alt="" src="data:image/jpeg;base64,<?php echo $jpeg_chunks; ?>">
</p>
<p>
Image PNG
<img alt="" src="data:image/png;base64,<?php echo $png_chunks; ?>">
</p>
</body>
</html>