I have found and modified a small php script for generating thumbnails
$src = (isset($_GET['file']) ? $_GET['file'] : "");
$width = (isset($_GET['maxwidth']) ? $_GET['maxwidth'] : 73);
$thname = "xxx";
$file_extension = substr($src, strrpos($src, '.')+1);
switch(strtolower($file_extension)) {
case "gif": $content_type="image/gif"; break;
case "png": $content_type="image/png"; break;
case "bmp": $content_type="image/bmp"; break;
case "jpeg":
case "jpg": $content_type="image/jpg"; break;
default: $content_type="image/png"; break;
}
if (list($width_orig, $height_orig, $type, $attr) = @getimagesize($src)) {
$height = ($width / $width_orig) * $height_orig;
}
$tn = imagecreatetruecolor($width, $height) ;
$image = imagecreatefromjpeg($src) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
imagejpeg($tn, './media/'.$thname.'.'.$file_extension, 90);
It generates and saves thumbnails perfectly.
How can I display those thumbnails on the fly?
I tryed to add this at the bottom of a script
header('Content-Type: image/jpeg');
imagegd($image);
but it says The image cannot be displayed because it contains errors. What am I doing wrong?
Try taking the closing ?> off at the end of the file and make sure that there is no whitespace at the top of the file. All it takes is on newline and the image will break.