Puedes descargar el código e imagen desde:
http://www.xombra.com/go.php?link=376El ejemplo consta de dos secciones:
* crear_thumbs.php *
<html>
<body>
<p>Original</p>
<p><img src="img/tux.jpg" alt="Tux" width="300" height="310" border="0" /></p>
<p>Thumbs</p>
<p> <img src='salida.php?imagen=img/tux.jpg' border="0" /></p>
</body>
</html>
y
salida.php
<?php
/*
Script bajo los términos y Licencia
GNU GENERAL PUBLIC LICENSE
Ver Terminos en:
http://www.gnu.org/copyleft/gpl.html
Traducción al español:
http://gugs.sindominio.net/gnu-gpl/gples.html
Autor: Hector A. Mantellini (Xombra)
*/
// Determinamos ancho y alto maximo para nuestro thumb
$anchura = 100;
$maxima_y = 100;
if (isset($_GET["imagen"]))
{ $nombre = $_GET["imagen"]; }
else
{ die("Error no ha declarado una imagen");}
# Determinamos el alto - ancho - tipo de imagen
$datos = getimagesize($nombre);
switch ($datos[2]) {
case 1:
$img = imagecreatefromgif($nombre);
break;
case 2:
$img = imagecreatefromjpeg($nombre);
break;
case 3:
$img = imagecreatefrompng($nombre);
break;
default:
die("Tipo de Imagen no valida");
}
$ratio = $datos[0] / $anchura;
$altura = $datos[1] / $ratio;
if($altura >= $maxima_y)
{ $anchura2 = $maxima_y * $anchura / $altura;
$altura = $maxima_y;
$anchura = $anchura2;
}
$thumb = imagecreatetruecolor($anchura,$altura);
imagecopyresampled($thumb, $img, 0, 0, 0, 0, $anchura, $altura, $datos[0], $datos[1]);
# Dependiendo del tipo de imagen le damos salida
switch ($datos[2]) {
case 1:
header("Content-type: image/gif");
imagegif($thumb);
break;
case 2:
header("Content-type: image/jpeg");
imagejpeg($thumb);
break;
case 3:
header("Content-type: image/png");
imagepng($thumb);
break;
default:
die("Tipo de Imagen no valida");
}
imagedestroy($thumb);
?>