I have some code below that is used to display resized thumbnails on the fly :
<?php
// Max Sizes
$th_max_width = 120; // Maximum width of the thumbnail
$th_max_height = 120; // Maximum height of the thumbnail
//-------------------
// File
$filename = $_GET['file'];
// Content type
header('Content-type: image/jpeg');
// Get image sizes
list($width, $height) = getimagesize($filename);
// Resize
$ratio = ($width > $height) ? $th_max_width/$width : $th_max_height/
$height;
$newwidth = round($width * $ratio);
$newheight = round($height * $ratio);
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
//Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight,
$width, $height);
// Output
imagejpeg($thumb);
?>
<?php
exit;
?>
But this is only for a single file type - in this case jpegs.
I've been trying to adapt it to display other image file types, but am unsure with the syntax around the three lines referencing the jpegs :
header('Content-type: image/jpeg');
to :
header('Content-type: image/jpeg, image/gif, image/png etc');
?
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
to :
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);
&& $source = imagecreatefromgif($filename);
&& $source = imagecreatefrompng($filename);
etc[/code]
or something like :
$thumb = imagecreatetruecolor($newwidth, $newheight);
if ( $filetype == "png") {
$source = imagecreatefrompng($filename);
} else if ( $filetype == "jpg") {
$source = imagecreatefromjpeg($filename);
} else ( $filetype == "gif") {
$source = imagecreatefromgif($filename);
};
But i'm obviously barking up the wrong tree, as I can't seem to get it to work.
Can anyone advise me of how the syntax for this would work?