Da adattare alle tue esigenze.
Utilizzo.
<img src="thumb.php?img=http://www.emmella.fr/ima/ART_CASIO_FX4000P.jpg" alt="">
Codice PHP:
<?php
//==============================================================================
// thumb.php
//
//==============================================================================
//----- Importante.
error_reporting(0);
$img = "quellochevuoi";
if (isset($_GET['img'])) {
$img = $_GET['img'];
} // if (isset($_GET['img']))
//--------- Percentuale di ridimensionamento
$pc = 0.50;
//--------- Dimensioni massime nel caso in cui l'immagine non esiste
$maxWidth = 400;
$maxHeight = 350;
$filename = $img;
//--------- Calcolo delle nuove dimensioni
$imgExiste = true;
list($width, $height) = getimagesize($filename);
if ($width == 0) {
$width = $maxWidth;
$imgExiste = false;;
} // if ($width == 0)
if ($height == 0) {
$height = $maxHeight ;
$imgExiste = false;
} // if ($height == 0)
$new_width = $width * $pc;
$new_height = $height * $pc;
//--------- Creazione dell'header
header('Content-type: image/jpeg');
//--------- Di default => L'immagine non esiste -> visualizza un'immagine con sfondo nero
$ni = imagecreatetruecolor($new_width,$new_height);
$black = imagecolorallocate($ni, 0, 0, 0);
imagefill($ni, 0, 0, $black);
if ($imgExiste) {
//--------- Creazione dell'immagine al volo
$image = imagecreatefromjpeg($filename);
//--------- Ridimensionamento
$image_p = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
imagecopy($ni, $image_p, 0, 0, 0, 0, $new_width, $new_height);
} // if ($imgExiste)
//--------- Display
imagejpeg($ni, null, 100);
imagedestroy ( $ni );
?>