Código PHP:
   <?php
function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth ) 
{
  $pathToImages = "img/";
  $dir = opendir( $pathToImages );
 
  while (false !== ($fname = readdir( $dir ))) {
    $info = pathinfo($pathToImages . $fname);
    if ( strtolower($info['extension']) == 'jpg' ) 
    {
      echo "Creating thumbnail for {$fname} <br />";
 
      $img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
      $width = imagesx( $img );
      $height = imagesy( $img );
 
      $new_width = $thumbWidth;
      $new_height = floor( $height * ( $thumbWidth / $width ) );
 
      $tmp_img = imagecreatetruecolor( $new_width, $new_height );
 
      imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
 
      imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
    }
  }
  closedir( $dir );
}
 
function createGallery( $pathToImages, $pathToThumbs ) 
{
  echo "Creating gallery.html <br />";
 
  echo  "<html>";
  echo  "<head><title>Thumbnails</title></head>";
  echo  "<body>";
  echo  "<table cellspacing=\"0\" cellpadding=\"2\" width=\"500\">";
  echo  "<tr>";
 
  $dir = opendir( $pathToThumbs );
 
  $counter = 0;
  while (false !== ($fname = readdir($dir)))
  {
    if ($fname != '.' && $fname != '..') 
    {
      echo  "<td valign=\"middle\" align=\"center\"><a href=\"{$pathToImages}{$fname}\">";
      echo  "<img src=\"{$pathToThumbs}{$fname}\" border=\"0\" />";
      echo  "</a></td>";
 
      $counter += 1;
      if ( $counter % 4 == 0 ) { $output .= "</tr><tr>"; }
    }
  }
  closedir( $dir );
 
  echo  "</tr>";
  echo  "</table>";
  echo  "</body>";
  echo  "</html>";
 
}
 
createThumbs("img/","thumbs/",100);
createGallery("img/","thumbs/");
?>    
 
