php galerie mit thumbnails für jpg Bilder in einem verzeichnis


<?php
if ($handle = opendir('.'))  {
  while (false !== ($file = readdir($handle)))  {

        if (".jpg" == substr($file,-4,4)) {
                $thumbfile=$file.".thumb";
                if (!is_file($thumbfile))  {

                list($width, $height) = getimagesize($file);
                $new_height = 100;
                $new_width = round($width*($new_height/$height));
                $source = imagecreatefromjpeg($file);
                $destination = imagecreate($new_width, $new_height);
                imagecopyresized($destination, $source, 0, 0, 0, 0,
 $new_width, $new_height, $width, $height);
                imagejpeg($destination, $thumbfile);
            }
            echo '<a href="' . $file . '"><img border=1 src="'.$thumbfile .
'" heigth="100" title="' . $file. '"></a>';
        }
    }

    closedir($handle);
}
?>

Kommentieren