<?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");
}
}
?>
Questo è uno script molto buona miniature =) Ecco un esempio:
$ path = Il percorso della cartella in cui l'immagine originale è. $ name = Il nome del file del file di cui vuoi fare una miniatura. $ thumbpath = Il percorso della directory in cui si desidera salvare la miniatura. $ maxwidth = la larghezza massima della miniatura in PX es. 100 (che sarà 100 px).
createThumbnail($path, $name, $thumbpath, $maxwidth);
Si noti che, a seconda delle immagini, JPG non avrà sempre un file di dimensioni inferiori rispetto a un file PNG, quindi assicuratevi di utilizzare quello giusto per la vostra situazione. http://lbrandy.com/blog/2008/10/my-first-and-last-webcomic/ – jimyi