#!/usr/bin/php
<?php

$top_top='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><head><title>';
$top_bot='</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" href="/home/krichel/krichel.css"/> 
</head><body><div>';

$title="Thomas Krichel's pictures dated ";
$head_start="<h1>pictures dated";
$head_end="by <a href=\"/home/krichel/\">Thomas Krichel</a></h1>\n";

$bottom='</div><p>
<a href="http://validator.w3.org/check?uri=referer"><img
    style="border: 0pt"
    src="/valid-xhtml10.png"
    alt="Valid XHTML 1.0!" height="31" width="88" /></a>
</p></body></html>';


$pic_url="/home/krichel/pictures";
$thumb_url="$pic_url/thumb";
$full_url="$pic_url/full";
$pic_dir="/home/krichel/public_html$pic_url";
$full_dir="$pic_dir/full";
$thumb_dir="$pic_dir/thumb";

# delete all the html thumbnail files
system("rm $pic_dir/*.html"); 

$dir=opendir("$full_dir");
while ($file = readdir($dir)) { 
  $date=substr($file,0,10);
  // File and new size
  $filename = "$full_dir/$file";
  $thumbname = "$thumb_dir/$file";
  $percent = 0.1;
  $date_file="$pic_dir/$date.html";
  if(! is_file($date_file)) {
    $file_resource=fopen($date_file,'a');
    fwrite($file_resource,"$top_top $title $date $top_bot");
    fwrite($file_resource,"$head_start $date $head_end");
    fclose($file_resource);
  }
  $file_resource=fopen($date_file,'a');
  $link="<a href=\"$full_url/$file\"><img src=\"$thumb_url/$file\" alt=\"picture of $date\"/></a>&nbsp;\n";
  fwrite($file_resource,$link);
  fclose($file_resource);

#  // Get new sizes
#  list($width, $height) = getimagesize($filename);
#  $newwidth = $width * $percent;
#  $newheight = $height * $percent;

#  // Load
#  $thumb = imagecreatetruecolor($newwidth, $newheight);
#  $source = imagecreatefromjpeg($filename);

#  // Resize
#  imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
#  // Output
#  imagejpeg($thumb,$thumbname);

}  

#
# final part. Look at all the file in the directory 
# and add the closing part of html. open the 
# directory again

$dir=opendir("$pic_dir");
while ($file = readdir($dir)) { 
  $sub=substr($file,11,4);
  if($sub=='html') { // it's a html file to close
    $file_resource=fopen("$pic_dir/$file",'a');
    fwrite($file_resource,"$bottom");
    fclose($file_resource);
  }
}

?>

Valid XHTML 1.0!