FileName: thumb.php

[sourcecode language='php']

< ?php

$im      = $_GET['im'];
$maxsize = $_GET['maxsize'];

if ($maxsize == '') {
    $image = exif_thumbnail($im, $width, $height, $type);

    if ($image) {
        header('Content-type: ' .image_type_to_mime_type($type));
        print $image;
    }
    else {
        print 'No thumbnail available';
    }   

} else {

$filename = $im;

$width  = $maxsize;
$height = $maxsize;

header('Content-type: image/jpeg');

list($width_orig, $height_orig) = getimagesize($filename);

if ($width && ($width_orig < $height_orig)) {
    $width = ($height / $height_orig) * $width_orig;
} else {
    $height = ($width / $width_orig) * $height_orig;
}

$image_p = imagecreatetruecolor($width, $height);
$image   = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

imagejpeg($image_p);
imagedestroy($image);
imageDestroy($image_p);
}
?>

[/sourcecode]

utilizzo:
thumb.php?im=uploads/immagine.jpg&maxsize=100

ridimensiona l'immagine con il lato maggiore non superiore a 100 pixels.

Se non viene specificata la dimensione massima, viene estratto (se disponibile) il thumbnail Exif contenuto nel file Jpeg (metodo molto più veloce nel caso di immagini di un certo peso).