<html>
<head>
<title>
www.sidenavn.dk</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?
/*************************************************************\
* Image resizer, version 1.3 alpha *
* Returns true on success, false if there are errors *
* If destination file is specified, resized picture will be *
* saved with the specified name. Else, it is shown to browser *
}*************************************************************{
* Created by XyborX (
www.xyborx.dk) *
* Feel free to use, modify and distribute, without profit. *
* I cannot be held liable for any damage this script might do *
\*************************************************************/
function imageresizejpeg($sourcefile,$maxwidth,$maxheight,$destinationfile=false)
{
if($img_src=@imagecreatefromjpeg($sourcefile))
{
$info=@getimagesize($sourcefile);
if($info[1]>$maxheight || $info[0]>$maxwidth)
{
$ratio_height=$maxheight/$info[1];
$ratio_width=$maxwidth/$info[0];
$ratio=min($ratio_width,$ratio_height);
$newwidth=intval($info[0]*$ratio);
$newheight=intval($info[1]*$ratio);
$img_dst=@imagecreatetruecolor($newwidth,$newheight);
@imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $newwidth, $newheight, $info[0], $info[1]);
if($destinationfile==false)
{
header("Content-type: image/jpeg");
@imagejpeg($img_dst);
}
else
@imagejpeg($img_dst,$destinationfile);
@imagedestroy($img_dst);
}
else
{
if($destinationfile==false)
{
header("Content-type: image/jpeg");
@imagejpeg($img_src);
}
else
@imagejpeg($img_src,$destinationfile);
}
@imagedestroy($img_src);
return true;
}
else
{
return false;
}
}
echo "<table border=\"0\" cellspacing=\"10\" cellpadding=\"10\">";
$i_tmp = 1;
if ($dir = opendir("./large"))
{
while($file = readdir($dir))
{
if(ereg(".jpg", strtolower($file)))
{
if(!is_file("./small/" . $file))
{
imageresizejpeg("./large/" . $file, 100, 100, "./small/" . $file);
}
if ($i_tmp == 1)
echo " <tr>\n";
echo " <td width=10 align=\"left\" valign=\"top\">\n";
echo " <a href=\"./large/" . $file . "\" target=\"_blank\"><img src=\"./small/" . $file . "\" border=\"0\"></a> ";
echo " </td>\n";
if($i_tmp == 4)
echo " </tr>\n";
$i_tmp++;
if ($i_tmp > 4)
$i_tmp = 1;
}
}
closedir($dir);
}
echo "</table>";
?>
</body>
</html>
De store billeder skal ligge i<html>
<head>
<title>
www.HM-GROUP.dk</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?
/*************************************************************\
* Image resizer, version 1.3 alpha *
* Returns true on success, false if there are errors *
* If destination file is specified, resized picture will be *
* saved with the specified name. Else, it is shown to browser *
}*************************************************************{
* Created by XyborX (
www.xyborx.dk) *
* Feel free to use, modify and distribute, without profit. *
* I cannot be held liable for any damage this script might do *
\*************************************************************/
function imageresizejpeg($sourcefile,$maxwidth,$maxheight,$destinationfile=false)
{
if($img_src=@imagecreatefromjpeg($sourcefile))
{
$info=@getimagesize($sourcefile);
if($info[1]>$maxheight || $info[0]>$maxwidth)
{
$ratio_height=$maxheight/$info[1];
$ratio_width=$maxwidth/$info[0];
$ratio=min($ratio_width,$ratio_height);
$newwidth=intval($info[0]*$ratio);
$newheight=intval($info[1]*$ratio);
$img_dst=@imagecreatetruecolor($newwidth,$newheight);
@imagecopyresampled($img_dst, $img_src, 0, 0, 0, 0, $newwidth, $newheight, $info[0], $info[1]);
if($destinationfile==false)
{
header("Content-type: image/jpeg");
@imagejpeg($img_dst);
}
else
@imagejpeg($img_dst,$destinationfile);
@imagedestroy($img_dst);
}
else
{
if($destinationfile==false)
{
header("Content-type: image/jpeg");
@imagejpeg($img_src);
}
else
@imagejpeg($img_src,$destinationfile);
}
@imagedestroy($img_src);
return true;
}
else
{
return false;
}
}
echo "<table border=\"0\" cellspacing=\"10\" cellpadding=\"10\">";
$i_tmp = 1;
if ($dir = opendir("./large"))
{
while($file = readdir($dir))
{
if(ereg(".jpg", strtolower($file)))
{
if(!is_file("./small/" . $file))
{
imageresizejpeg("./large/" . $file, 100, 100, "./small/" . $file);
}
if ($i_tmp == 1)
echo " <tr>\n";
echo " <td width=10 align=\"left\" valign=\"top\">\n";
echo " <a href=\"./large/" . $file . "\" target=\"_blank\"><img src=\"./small/" . $file . "\" border=\"0\"></a> ";
echo " </td>\n";
if($i_tmp == 4)
echo " </tr>\n";
$i_tmp++;
if ($i_tmp > 4)
$i_tmp = 1;
}
}
closedir($dir);
}
echo "</table>";
?>
</body>
</html>
Struktur:
index.php
|- large
|- billede1.jpg
|- small
|- automatisk genererede thumbnails
Spørgsmål?
/mikl-dk