Mht.: $d->read og $d->close er der et eksempel her:
http://dk2.php.net/manual/en/class.dir.phpgetimagesize() returnerer et array hvor index 3 indeholder en streng med width og height til brug i et img tag (hvis det er det du skal bruge):
http://dk2.php.net/manual/en/function.getimagesize.phpHer er koden rettet lidt til:
<?php
$dir = "img"; // Mappe med original billeder
$thumbs = "thumbs"; // Mappe til thumbnails
$size = 100; // Max bredde/højde (pixler)
function Thumb($sourcefile, $targetfile, $size) {
$source_id = imageCreateFromJPEG($sourcefile);
$source_x = imagesx($source_id);
$source_y = imagesy($source_id);
$delta = $size/max($source_x,$source_y);
$dest_x = round($source_x*$delta);
$dest_y = round($source_y*$delta);
$target_id=imagecreatetruecolor($dest_x, $dest_y);
imagecopyresampled($target_id,$source_id,0,0,0,0, $dest_x,$dest_y, $source_x,$source_y);
imagejpeg($target_id,$targetfile, 100);
}
$out = "";
$d = dir($dir);
while (false !== ($pic = $d->read())) {
$navn = explode(".", $pic);
$ext = array_pop($navn);
if ($ext == 'jpg' || $ext == 'jpeg') {
$navn = "$dir/$thumbs/".implode(".", $navn)."_thumb.".$ext;
$sti = "$dir/$pic";
if (!file_exists($navn)) Thumb($sti, $navn, $size);
$img_size = getimagesize($navn);
$out .= "<a href='".$sti."'><img style='border: thin solid blue' src='".$navn."' alt='$pic' title='$pic' $img_size[3] /></a>\n";
}
}
$d->close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html>
<head>
<title>Thumbs</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<style type="text/css">
body {
background: #d0f0ff;
}
#x {
text-align: center;
}
</style>
</head>
<body>
<div id="x"><?php echo $out;?></div>
</body>
</html>