first, i´m sorry that i not managed to write a better explanation.
i think i have gone much to far for someone who has never done something with gd2-lib.
and the most important thing is, that i have made a mistake - i have forgotten to initialize some variables with content :bemused:
you are right, the other example is easier, but it is only resizing jpg-images and is not resizing a image to a wanted dimension.
here a functional code (i´ve tested it):
/
file: thumbnail.php
*/
// create full path to image
$original_image = $_SERVER['DOCUMENT_ROOT'] . $_GET["original_image"];
/*
* Reading imageinformation
* ARRAY [0] width
* ARRAY [1] height
* ARRAY [2] formt
* ARRAY [3] HTML-width und -height (height=+++ width=+++)
*/
$format = getimagesize($original_image);
// different functions for different imageformats (create new image with old content)
switch($format[2])
{
// GIF
case 1:
$src = imagecreatefromgif($original_image);
break;
// JPEG
case 2:
$src = imagecreatefromjpeg($original_image);
break;
// PNG
case 3:
$src = imagecreatefrompng($original_image);
break;
}
// original image is more height than width
if ($format[1] > $format[0] && $format[1] > $_GET["thmb_height"])
{
$factor = $format[1] / $_GET["thmb_height"];
}
// original image is more width than height
elseif ($format[0] > $format[1] && $format[0] > $_GET["thmb_width"])
{
$factor = $format[0] / $_GET["thmb_width"];
}
// original image is quadratical and greater than thumbnail
elseif ($format[0] == $format[1] && $format[0] > $_GET["thmb_width"])
{
$factor = $format[0] / $_GET["thmb_width"];
}
// original image is smaller than thumnbnail
else
{
// direkt output
header ("Location: " . $_GET["original_image"]);
exit();
} // end if
// proportional resizing
$x = $format[0] / $factor;
$y = $format[1] / $factor;
$new_src = imagecreatetruecolor($x, $y);
ImageCopyResampled($new_src, $src, 0, 0, 0, 0, $x, $y, $format[0], $format[1]);
// header and imageoutput
switch($format[2])
{
// GIF
case 1:
header('Content-Type: ' . image_type_to_mime_type(IMAGETYPE_GIF));
(function_exists("imagegif"))? imagegif($new_src): imagepng($new_src);
break;
// JPEG
case 2:
header('Content-Type: ' . image_type_to_mime_type(IMAGETYPE_JPEG));
imagejpeg($new_src, "", 85);
break;
// PNG
case 3:
header('Content-Type: ' . image_type_to_mime_type(IMAGETYPE_PNG));
imagepng($new_src);
break;
// Default
default:
header('Content-Type: ' . image_type_to_mime_type(IMAGETYPE_JPEG));
imagejpeg($new_src, "", 85);
}
// free image from memory
imagedestroy($new_src);
/
file: test.htm
*/
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Testpage</title>
</head>
<body>
<img border="0" vspace="4" hspace="4" src="thumbnail.php?thmb_width=50&thmb_height=50&original_image=/test.jpg">
</body>
</html>
perhaps there is a way to make it more easier...
cu
chris