<?php
function createThumbnail($imageDirectory, $imageName, $thumbDirectory, $thumbWidth) {
$explode = explode(".", $imageName);
$filetype = $explode[1];
if ($filetype == 'jpg') {
$srcImg = imagecreatefromjpeg("$imageDirectory/$imageName");
} else
if ($filetype == 'jpeg') {
$srcImg = imagecreatefromjpeg("$imageDirectory/$imageName");
} else
if ($filetype == 'png') {
$srcImg = imagecreatefrompng("$imageDirectory/$imageName");
} else
if ($filetype == 'gif') {
$srcImg = imagecreatefromgif("$imageDirectory/$imageName");
}
$origWidth = imagesx($srcImg);
$origHeight = imagesy($srcImg);
$ratio = $origWidth/$thumbWidth;
$thumbHeight = $origHeight/$ratio;
$thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresized($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $origWidth, $origHeight);
if ($filetype == 'jpg') {
imagejpeg($thumbImg, "$thumbDirectory/$imageName");
} else
if ($filetype == 'jpeg') {
imagejpeg($thumbImg, "$thumbDirectory/$imageName");
} else
if ($filetype == 'png') {
imagepng($thumbImg, "$thumbDirectory/$imageName");
} else
if ($filetype == 'gif') {
imagegif($thumbImg, "$thumbDirectory/$imageName");
}
}
?>
Este es un muy buen guión miniatura =) He aquí un ejemplo:
$ path = La ruta de la carpeta en la que la imagen original es. $ name = El nombre de archivo del archivo del que quiere hacer una miniatura. $ thumbpath = La ruta al directorio donde desea guardar la miniatura. $ maxwidth = el ancho máximo de la miniatura en PX, por ejemplo. 100 (que será 100px).
createThumbnail($path, $name, $thumbpath, $maxwidth);
Tenga en cuenta que dependiendo de las imágenes, JPG no siempre tendrá un tamaño de archivo más pequeño que un PNG, por lo que debe asegurarse de que está utilizando el adecuado para su situación. http://lbrandy.com/blog/2008/10/my-first-and-last-webcomic/ – jimyi