sortfile // (and then edit with vi) // /////////////////////////////////////////////////////////////////////////////// // // Default Settings - change here or create a config.php that overrides them // If using a config.php make sure you put PHP tags around the lines of code $title = "Buffy's disc brakes"; // Title for the overall web page $marginsize = 150; // Size of left-hand frame with thumbnails $pagecolor = "#FFFFFF"; // Default background color of pages $textcolor = "#000000"; // Default text color for all pages $imagesize = false; // Resize images to fit window? true/false $thumb = "./thumb"; // Directory where thumbnails are stored $half = "./half"; // Directory where half pics are stored $getcomment = "/usr/local/bin/rdjpgcom"; // To extract JPG comments (part of libjpeg) $getexif = "/usr/local/bin/jhead"; // to extract camera EXIF info. $introfile = "intro.html"; // If it exists, will be displayed up front $headerfile = "header.html"; // If it exists, will be included at top $footerfile = "footer.html"; // If it exists, will be included at bottom $sortfile = "sortfile"; // If it exists, contains filenames in order if (file_exists("config.php")) { // Settings in here will override defaults include("config.php"); } /////////////////////////////////////////////////////////////////////////////// if (!function_exists("ImageTypes")) { PrintHeader(); echo "

Sorry, but this script requires that your copy of PHP has been compiled with support for images.

"; echo "

configure --with-gd ...

"; exit; } function RemoveNewLines (&$item, $key) { $item = chop($item); } function GetFileList( $dirname="." ) { // Finds all the images // First check to see if there's a file called $sortfile // that contains a sorted list of filenames, one per line // otherwise, will default to all files in alphabetical order global $sortfile; $files = array(); if (file_exists($sortfile)) { $files = file($sortfile); array_walk($files, 'RemoveNewLines'); } else { $dir = opendir( $dirname ); while( $file = readdir( $dir ) ) { if (eregi("\.jpe?g$", $file) || eregi("\.gif$", $file) || eregi("\.png$", $file)) { $files[] = $file; } } sort($files); } return $files; } function GetNeighbours($imagelist, $currimage, &$previmage, &$nextimage) { // For a given image, return the next and previous ones $lastimage = count($imagelist) - 1; for ( $i=0; $i<=$lastimage; $i++) { if ("half/".$imagelist[$i] == $currimage) { if ($i == 0) { $nextimage = "half/".$imagelist[$i+1]; $previmage = NULL; return; } else if ($i == $lastimage) { $previmage = "half/".$imagelist[$i-1]; $nextimage = NULL; return; } else { $previmage = "half/".$imagelist[$i-1]; $nextimage = "half/".$imagelist[$i+1]; return; } } } $previmage = NULL; $nextimage = NULL; return; } function PrintHeader() { global $headerfile; global $pagecolor; global $textcolor; if (file_exists($headerfile)) { include($headerfile); } else { echo "\n"; } } function PrintFooter() { global $footerfile; global $title; if (file_exists($footerfile)) { include($footerfile); } else { echo "

"; echo "$title

\n"; echo ".\n"; } } function PrintEXIF($image) { global $getexif; echo "

"; $fullimage = ereg_replace("half/", "", $image); $exif = popen(EscapeShellCmd("$getexif $fullimage"), "r"); while (!feof ($exif)) { $line = fgets ($exif, 1024); echo "
$line"; } pclose($exif); } function CleanFilename($filename) { return str_replace(" ","%20",$filename); } function ReadImageFromFile($filename, $type) { $imagetypes = ImageTypes(); switch ($type) { case 1 : if ($imagetypes & IMG_GIF) return $im = ImageCreateFromGIF($filename); break; case 2 : if ($imagetypes & IMG_JPEG) return ImageCreateFromJPEG($filename); break; case 3 : if ($imagetypes & IMG_PNG) return ImageCreateFromPNG($filename); break; default: return 0; } } function WriteImageToFile($im, $filename, $type) { switch ($type) { case 1 : return ImageGIF($im, $filename); case 2 : return ImageJpeg($im, $filename, 70); case 3 : return ImagePNG($im, $filename); default: return false; } } function PrintSlideshowForm ($nextimage, $slide=0) { $common = "index.php?image=half/$nextimage&slide="; $options = array (1 => "1 seconds", 3 => "3 seconds", 5 => "5 seconds", 10 => "10 seconds", 20 => "20 seconds", 30 => "30 seconds", 40 => "40 seconds", 50 => "50 seconds", 60 => "1 minute"); echo "

"; echo ""; } if ($intro) { // Print initial info in main frame if (file_exists($introfile)) { include($introfile); } else { PrintHeader(); echo "

$title

"; echo "

Select images from the left

"; } die; } if ($margin) { // Create a list of thumbnails if (!file_exists($thumb)) { if ( ! mkdir($thumb, 0755)) { echo "Error: could not create thumb dir - check write permissions"; die; } } if (!file_exists($half)) { if ( ! mkdir($half, 0755)) { echo "Error: could not create half dir - check write permissions"; die; } } PrintHeader(); $imagelist = GetFileList(); while ( list($i,$image) = each ($imagelist) ) { $thumbimage = $thumb."/".$image; $thumb_exists = file_exists($thumbimage); if (!$thumb_exists) { // Try to create the thumbnail $size = GetImageSize($image); $width = $size[0]; $height = $size[1]; $type = $size[2]; if ($im = ReadImageFromFile($image, $type)) { $twidth = $margin - 20; $theight = ($twidth / $width) * $height; if (function_exists("ImageCreateTrueColor")) { $im2 = ImageCreateTrueColor($twidth,$theight); } else { $im2 = ImageCreate($twidth,$theight); } if (function_exists("ImageCopyResampled")) { ImageCopyResampled($im2,$im,0,0,0,0,$twidth,$theight,$width,$height); } else { ImageCopyResized($im2,$im,0,0,0,0,$twidth,$theight,$width,$height); } if (WriteImageToFile($im2, $thumbimage, $type)) { $thumb_exists = true; } } } $halfimage = $half."/".$image; $half_exists = file_exists($halfimage); if (!$half_exists) { // Try to create the halfnail $size = GetImageSize($image); $width = $size[0]; $height = $size[1]; $type = $size[2]; if ($im = ReadImageFromFile($image, $type)) { $twidth = $width / 2; $theight = $height / 2; if (function_exists("ImageCreateTrueColor")) { $im2 = ImageCreateTrueColor($twidth,$theight); } else { $im2 = ImageCreate($twidth,$theight); } if (function_exists("ImageCopyResampled")) { ImageCopyResampled($im2,$im,0,0,0,0,$twidth,$theight,$width,$height); } else { ImageCopyResized($im2,$im,0,0,0,0,$twidth,$theight,$width,$height); } if (WriteImageToFile($im2, $halfimage, $type)) { $half_exists = true; } } } $comment = Exec(EscapeShellCmd("$getcomment $image")); if (! $comment) { $comment = $image; } $image = CleanFilename($image); $thumbimage = CleanFilename($thumbimage); // The d=d.html was added to help dumb caches echo ""; if ($thumb_exists) { echo "\"$comment\""; } else { echo "$comment"; } echo "

\n"; } die; } if ($image) { if (!file_exists($image)) { echo "Error: Strangely, that picture doesn't exist"; die; } $imagelist = GetFileList(); GetNeighbours($imagelist, $image, $previmage, $nextimage); if ($slide && $nextimage) { echo ""; } else { $slide = "0"; } PrintHeader(); echo ""; $fullimage = ereg_replace("half/", "", $image); echo ""; } if ($nextimage) { echo ""; echo ""; } echo "
Full Size"; if ($previmage) { echo "
"; PrintSlideshowForm($nextimage, $slide); echo "
"; $image = CleanFilename($image); $comment = Exec(EscapeShellCmd("$getcomment $image")); echo "

$comment

"; if ($imagesize) { $imagewidth = "WIDTH=100%"; } echo "

"; PrintEXIF($image); PrintFooter(); die; } ?> <? echo $title ?> This site works best wih frames, which your browser doesn't support. You can still browse this photo album, though, by starting <A HREF="index.php?margin=<? echo $marginsize ?>">here</A>