/////////////////////////////////////////////////////////////////////////////// // Martin's Photo Frame, v3.3 http://dougiamas.com/photoframe // // Displays a directory full of images (JPEG, PNG, GIF) simply and easily. // It will also create thumbnails and display JPEG comments if it finds them. // I am placing this script in the Public Domain - use it as you wish. // // Requirements: A web server with this software (note minimum versions): // - PHP 4.0.2 http://www.php.net // - GD 1.8.3 http://www.boutell.com/gd // - libjpeg 6b ftp://ftp.uu.net/graphics/jpeg/ // // How to use: 1. Store all your images in a directory on your server // 2. Save this file in that directory as index.php // 3. Make sure the web server has write permissions so // that it can create a sub directory for thumbnails. // eg mkdir thumb ; chown nobody thumb // (optional) 4. Change any of the settings below to suit. // (optional) 5. Add an intro.html file if you like. // (optional) 6. Add header.html and footer.html files if you want // to change page colours, layout or styles. // (optional) 7. Add a sortfile if you want to control the order of // the photos, rather than the default alphabetical order. // Just make a simple text file with one filename per line. // eg ls -1 *.jpg *.png > 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 "
"; 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 "";
}
if ($intro) { // Print initial info in main frame
if (file_exists($introfile)) {
include($introfile);
} else {
PrintHeader();
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 "| Full Size"; if ($previmage) { echo " | "; } if ($nextimage) { echo " | "; echo " | "; PrintSlideshowForm($nextimage, $slide); echo " | "; } echo "