Online-Beispiel ist schlecht, aber hier ist der Code:
Skript zur Bilderzeugung:
<?PHP
if (isset($_GET["file"])) $file = $_GET["file"];
else $file = null;
if (isset($_GET["imgsize"])) $imgsize = $_GET["imgsize"];
if ($file != null && is_readable($file)) {
$size = @getimagesize($file);
$imgwidth = $size[0];
$imgheight = $size[1];
if ($imgsize==750) {
if ($imgwidth > 750) $maxwidth = 750;
else $maxwidth = $imgwidth;
} else {
$maxwidth = $imgsize;
}
if ($imgwidth > $maxwidth) {
$thheight = $imgheight / ($imgwidth / $maxwidth);
$thheight = round($thheight);
$thwidth = $maxwidth;
} else {
$thwidth = $imgwidth;
$thheight = $imgheight;
}
$source = ImageCreateFromJPEG ($file);
header("Content-type: image/jpg");
$dest = imagecreatetruecolor($thwidth, $thheight);
imagecopyresampled ($dest, $source, 0, 0, 0, 0, $thwidth, $thheight, $imgwidth, $imgheight);
imagejpeg($dest);
imagedestroy($dest);
imagedestroy($source);
}
?>
Skript zur Linkerzeugung und Einfügen des verkleinerten Bildes:
<?PHP
$size = @getimagesize($imgf);
$imgwidth = $size[0] + 20;
$imgheight = $size[1] + 20;
if ($size[0] > 150) {
echo "<a href='resizeimage.php?file=$imgf&imgsize=750'";
echo "target='_blank' onclick="NewWindow(";
echo "'resizeimage.php?file=$imgf&imgsize=750'";
echo ",'_blank'";
echo ",'$imgwidth','$imgheight','no','center'); return false" id='link-bold-m'>";
}
echo "<img src='resizeimage.php?file=$imgf&imgsize=150' border='0' alt='$title'>";
if ($size[0] > 150) echo "</a>";
?>
MfG,
HP-Bauer