Topic: Customized buildgallery.php

FYI...

This is more for those who have some knowledge in PHP, but anyone could use it and figure out on your own is find.

I modified the buildgallery.php to do the following for me...

The original version requires you to have one copy in each sub-directory of the album you have to create the XML file. The modified version will search all the albums and create the XML file for you automatically for each of the album and re-generate a new index.html file you.

It will also, using the EXIF function call appent the EXIF information from your picture into the caption field of the tag.

Use at your own risk...


Below is the sample code or you could download it here
http://www.photographybykevin.net/index … mp;pages=2

<?
// -----------------------
// buildgallery.php 
// -----------------------
// by&#58;
// Mario - mariohm@fibertel.com.ar
// Mike Peck - www.mikecpeck.com 
// Mike Johnson - mike@solanosystems.com
// Christian Machmeier - www.redsplash.de 
// Airtight - www.airtightinteractive.com
//
// DESCRIPTION
// -----------------------
// This script automatically generates the XML document and thumbnails for SimpleViewer 
// www.airtightinteractive.com/simpleviewer/
//
// TO USE
// -----------------------
// Instructions are at&#58; www.airtightinteractive.com/simpleviewer/auto_instructions.html
//
// SET GALLERY OPTIONS HERE
// -----------------------
// Set Gallery options by editing this text&#58;
//
// -----------------------------------------------------------------------------
// START MODIFICATION BY K. NGUYEN-TU JUNE 2006
// USAGE&#58; COPY BUILDGALLERY.PHP TO GALLERY PATH
// SET PERMISSION TO 755
// POINT URL TO BUILDGALLERY.PHP TO CREATE XML FILE
// EXAMPLE&#58; HTTP&#58;//WWW.DOMAIN.COM/PICTURES/BUILDGALLERY.PHP
//------------------------------------------------------------------------------
// END OF OPTIONS
// -----------------------

// Open Current Director and obtain all sub directories
$dirfolder = opendir&#40;'./'&#41;;
while &#40;&#40;$dirfile = readdir&#40;$dirfolder&#41;&#41; !== false&#41; &#123;
  if&#40;$dirfile != "." && $dirfile != ".."&#41;&#123;
    if&#40;is_dir&#40;$dirfile&#41;&#41; &#123; 
      maincode&#40;$dirfile&#41;; // call maincode function to build xml file
      buildindex&#40;$dirfile&#41;; // call buildindex function to create index.php
    &#125;
  &#125;
&#125;
closedir&#40;$dirfolder&#41;;


// Create INDEX.PHP in each sub gallery
function buildindex&#40;$dirfile&#41;&#123;
  // Set Variable & print info
    $carreturn = "rn";
    $indexwrite  = '<script type="text/javascript" src="flashobject.js"></script>'.$carreturn;
    $indexwrite .= '<style type="text/css">'.$carreturn;
//      $indexwrite .= 'html &#123;height&#58; 100%;&#125;'.$carreturn;
      $indexwrite .= '#flashcontent &#123; height&#58; 100%; &#125;'.$carreturn;
//      $indexwrite .= '#header &#123;width&#58; 100%; height&#58; 100%;&#125;'.$carreturn;
//      $indexwrite .= '#footer &#123;width&#58; 100%; height&#58; 100%;&#125;'.$carreturn;
//      $indexwrite .= 'body &#123; height&#58; 100%; margin&#58; 0; padding&#58; 0;&#125;'.$carreturn;
    $indexwrite .= '</style>'.$carreturn;
    $indexwrite .= '<? $xmlpath = "./pictures/'.$dirfile.'/gallery.xml"; ?>'.$carreturn;
    $indexwrite .= '<div id="flashcontent">SimpleViewer requires Macromedia Flash. <a href="http&#58;//www.macromedia.com/go/getflashplayer/">Get Macromedia Flash.</a> If you have Flash installed, <a href="index.html?detectflash=false">click to view gallery</a></div>'.$carreturn;
    $indexwrite .= '<script type="text/javascript">'.$carreturn;
    $indexwrite .= '    var fo = new FlashObject&#40;"viewer.swf", "viewer","700", "750", "0", "#000000"&#41;;'.$carreturn;
    $indexwrite .= '    fo.addParam&#40;"scale", "noscale"&#41;;'.$carreturn;
    $indexwrite .= '    fo.addParam&#40;"quality", "best"&#41;;'.$carreturn;
//    $indexwrite .= '    fo.addParam&#40;"wmode", "transparent"&#41;;'.$carreturn;
    $indexwrite .= '    fo.addParam&#40;"FlashVars", "xmlDataPath=<?=$xmlpath?>"&#41;;'.$carreturn;
    $indexwrite .= '    fo.write&#40;"flashcontent"&#41;;'.$carreturn;
    $indexwrite .= '</script>'.$carreturn;
    $indexwrite .= $carreturn.$carreturn;

    $file = "./".$dirfile."/index.php";
    if &#40;!$file_handle = fopen&#40;$file,"w"&#41;&#41; &#123; 
       print "<br>Cannot open XML document&#58; $file<br>"; 
    &#125;  elseif &#40;!fwrite&#40;$file_handle, $indexwrite&#41;&#41; &#123; 
       print "<br>Cannot write to PHP document&#58; $file<br>";   
    &#125;else&#123;
       print "<br>Successfully created PHP document&#58; $file<br>";   
    &#125;
    fclose&#40;$file_handle&#41;; 
&#125;

// Main Code Of BUILDGALLERY.PHP
function maincode&#40;$dirfile&#41; &#123;

// Read current URL Path Location Of BUILDGALLERY.PHP
$current_url = $_SERVER&#91;'HTTP_HOST'&#93;; // sample domain.com
$current_path = $_SERVER&#91;'REQUEST_URI'&#93;; // sample /pictures/gallery1/buildgallery.php
// $url_string = 'http&#58;//'.$current_url.$current_path; // sample http&#58;//www.domain.com/pictures/gallery1/buildgallery.php
$url_string = $current_path; // sample http&#58;//www.domain.com/pictures/gallery1/buildgallery.php
$url_string = str_replace &#40;'/buildgallery.php', '', $url_string&#41;; //Truncate buildgallery.php from URL

// Misc Settings&#58; Set Text Color, Frame Color, Frame Color, Border Size, Rows, Columns, etc.,
$carreturn = "rn";
$pattern = '/&#40;<&#40;?&#58;&#91;^<>&#93;+&#40;?&#58;"&#91;^"&#93;*"|'&#91;^'&#93;*'&#41;?&#41;+>&#41;/';
$textcolor = "0xFFFFFF";
$framecolor = "0xFFFFFF";
$bgcolor = "0x181818";
$framewidth = "0";
$stagepadding = "0";
$thumbnailcolumns = "7"; // How many columns for thumbnails
$thumbnailrows = "1"; // How many rows for thumbnails
$navposition = "bottom"; // Thumbnails position &#40;right, left, top, bottom&#41;
$gallery_title = ""; //Name of Gallery
$showDownloadLinks = true; // Show Download Links &#40;True, False&#41;
$linkpath = $url_string."/".$dirfile."/images/"; // sample http&#58;//www.domain.com/pictures/gallery1/images/
$thumbpath = $url_string."/".$dirfile."/thumbs/"; // sample http&#58;//www.domain.com/pictures/gallery1/thumbs/
$options .= '<SIMPLEVIEWER_DATA maxImageWidth="600" maxImageHeight="550" textColor="'.$textcolor.'" frameColor="'.$framecolor.'" bgColor="'.$bgcolor.'" frameWidth="'.$framewidth.'" stagePadding="'.$stagepadding.'" thumbnailColumns="'.$thumbnailcolumns.'" thumbnailRows="'.$thumbnailrows.'" navPosition="'.$navposition.'" navDirection="LTR" title="'.$gallery_title.'" enableRightClickOpen="true" backgroundImagePath="" imagePath="'.$linkpath.'" thumbPath="'.$thumbpath.'">';

print "Creating XML and thumbnails for SimpleViewer.<br>"; 
print "-------------------------------------------------<br><br>"; 
//Get GD imaging library info
echo $dirfile;
$tgdInfo    = getGDversion&#40;&#41;; 
if &#40;$tgdInfo == 0&#41;&#123; 
    print "Note&#58; The GD imaging library was not found on this Server. Thumbnails will not be created. Please contact your web server administrator.<br><br>";
&#125;

if &#40;$tgdInfo < 2&#41;&#123;
    print "Note&#58; The GD imaging library is version ".$tgdInfo." on this server. Thumbnails will be reduced quality. Please contact your web server administrator to upgrade GD version to 2.0.1 or later.<br><br>";
&#125;

//loop thru images 
$xml = '<?xml version="1.0" encoding="UTF-8" ?>'.$options.$carreturn;
$imagedir = "./".$dirfile."/images/";
$folder = opendir&#40;$imagedir&#41;;
while&#40;$file = readdir&#40;$folder&#41;&#41; &#123;    
    if &#40;$file&#91;0&#93; != "." && $file&#91;0&#93; != ".."&#41; &#123;
     if &#40;$file&#91;0&#93; != "Thumbs.db"&#41; &#123;
       $imagedirfile = $imagedir.$file;
       $files&#91;$file&#93; = filemtime&#40;$imagedirfile&#41;;
     &#125;
  &#125;        
&#125;    
// now sort by date modified
arsort&#40;$files&#41;;
foreach&#40;$files as $key => $value&#41; &#123;

  if &#40;$key != "Thumbs.db"&#41; &#123;
     $xml .= '<IMAGE>'.$carreturn;
     $xml .= '<NAME>'.$key.'</NAME>'.$carreturn;
     
     //Obtain EXIF Information From Pictures
     $exif_file = "./".$dirfile."/images/".$key;
     $exif = exif_read_data&#40;$exif_file, EXIF, TRUE&#41;;
    foreach &#40;$exif as $key1 => $section1&#41; &#123;
      foreach &#40;$section1 as $name1 => $val&#41; &#123;
//        echo "$key1.$name1&#58; $val<br />n";
        if &#40;$name1 == "ApertureFNumber" && $key1 == "COMPUTED"&#41; &#123;
            $ApertureFNumber = "ApertureFNumber&#58; ".$val;
            
        &#125; elseif &#40;$name1 == "ExposureTime" && $key1 == "EXIF"&#41; &#123;
            list&#40;$a, $b&#41; = split &#40;"/", $val&#41;;
            $ab = $b / $a;
            $ExposureTime = "ExposureTime&#58; 1/".$ab;
        &#125; elseif &#40;$name1 == "FocalLength" && $key1 == "EXIF"&#41; &#123;
            list&#40;$a, $b&#41; = split &#40;"/", $val&#41;;
            $ab = $a / $b;
            $FocalLength = "FocalLength&#58; ".$ab."mm";
        &#125;
       
      &#125;
    &#125;


//     while&#40;list&#40;$k,$v&#41;=each&#40;$exif&#41;&#41; &#123;
//    echo "$k&#58; $v<br>n";
//   &#125;
     
     
     //add auto captions&#58; 'Image X'
     if &#40;$showDownloadLinks&#41;&#123;        
        $xml .= '<CAPTION><!&#91;CDATA&#91;<A href="'.$linkpath.''.$key.'" target="_blank" class="xmlcaption"><center><b>OPEN LARGER IMAGE&#58; '.$key.'<br>'.$ApertureFNumber.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$ExposureTime.'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$FocalLength.'<br></b><center></A>&#93;&#93;></CAPTION>'.$carreturn;
     &#125;else&#123;
        $xml .= '<CAPTION></CAPTION>'.$carreturn;
     &#125;
     $xml .= '</IMAGE>'.$carreturn;
     print "- Created Image Entry for&#58; $key<br>";  
    
     if &#40;!file_exists&#40;"./".$dirfile."/thumbs/".$key&#41;&#41;&#123;                    
         if &#40;createThumb&#40;$key, $dirfile&#41;&#41;&#123;
             print "- Created Thumbnail for&#58; $key<br>";              
        &#125;
   &#125;                                    
    &#125;
&#125;






closedir&#40;$folder&#41;;

$xml .= '</SIMPLEVIEWER_DATA>';
$file = "./".$dirfile."/gallery.xml";   
if &#40;!$file_handle = fopen&#40;$file,"w"&#41;&#41; &#123; 
    print "<br>Cannot open XML document&#58; $file<br>"; 
&#125;  elseif &#40;!fwrite&#40;$file_handle, $xml&#41;&#41; &#123; 
    print "<br>Cannot write to XML document&#58; $file<br>";   
&#125;else&#123;
    print "<br>Successfully created XML document&#58; $file<br>";   
&#125;
fclose&#40;$file_handle&#41;;  
&#125;
                                                                        
// &#125;&#125;&#125;
// &#123;&#123;&#123; createThumb&#40;&#41;

/**
* Create a squared thumbnail from an existing image.
* 
* @param    string        $file        Location and name where the file is stored .
* @return    boolean
* @access    public
* @author    Christian Machmeier
*/
function createThumb&#40;$fileName, $dirfile&#41;
&#123;
    
    // Get information about the installed GD.
    $gdVersion = getGDversion&#40;&#41;;
    
    if &#40;$gdVersion == false&#41; &#123;
        return false;
    &#125;
    
    $file = "./".$dirfile.'/images/'.$fileName;
    $fileDest = "./".$dirfile.'/thumbs/'.$fileName;
    
    echo $file;
    echo $fileDest;
    
    
    // Get the image dimensions.
    $dimensions = @getimagesize&#40;$file&#41;;
    $width        = $dimensions&#91;0&#93;;
    $height        = $dimensions&#91;1&#93;;    
    
    $outputX  = 65;
    $outputY  = 65;
    $quality  = 85;
    
    // The image is of vertical shape.
    if &#40;$width < $height&#41; &#123;
        $deltaX   = 0;
        $deltaY   = &#40;$height - $width&#41; / 2;
        $portionX = $width;
        $portionY = $width;
        
    // The image is of horizontal shape.
    &#125; else if &#40;$width > $height&#41; &#123;
        $deltaX   = &#40;$width - $height&#41; / 2;
        $deltaY   = 0;
        $portionX = $height;
        $portionY = $height;
        
    // The image is of squared shape.
    &#125; else &#123;
        $deltaX   = 0;
        $deltaY   = 0;
        $portionX = $width;
        $portionY = $height;
    &#125;
    

    $imageSrc  = @imagecreatefromjpeg&#40;$file&#41;;

    // The thumbnail creation with GD1.x functions does the job.
    if &#40;$gdVersion < 2&#41; &#123;
        
        // Create an empty thumbnail image.
        $imageDest = @imagecreate&#40;$outputX, $outputY&#41;;
        
        // Try to create the thumbnail from the source image.
        if &#40;@imagecopyresized&#40;$imageDest, $imageSrc, 0, 0, $deltaX, $deltaY, $outputX, $outputY, $portionX, $portionY&#41;&#41; &#123;
            
            // save the thumbnail image into a file.
            @imagejpeg&#40;$imageDest, $fileDest, $quality&#41;;
            
            // Delete both image resources.
            @imagedestroy&#40;$imageSrc&#41;;
            @imagedestroy&#40;$imageDest&#41;;
            
            return true;
            
        &#125;
        
    &#125; else &#123;    
        // The recommended approach is the usage of the GD2.x functions.
        
        // Create an empty thumbnail image.
        $imageDest = @imagecreatetruecolor&#40;$outputX, $outputY&#41;;
        
        // Try to create the thumbnail from the source image.
        if &#40;@imagecopyresampled&#40;$imageDest, $imageSrc, 0, 0, $deltaX, $deltaY, $outputX, $outputY, $portionX, $portionY&#41;&#41; &#123;
            
            // save the thumbnail image into a file.
            @imagejpeg&#40;$imageDest, $fileDest, $quality&#41;;
            
            // Delete both image resources.
            @imagedestroy&#40;$imageSrc&#41;;
            @imagedestroy&#40;$imageDest&#41;;
            
            return true;            
        &#125;        
    &#125;
    
    return false;
&#125;
        
function getGDversion&#40;&#41; &#123;
   static $gd_version_number = null;
   if &#40;$gd_version_number === null&#41; &#123;
       // Use output buffering to get results from phpinfo&#40;&#41;
       // without disturbing the page we're in.  Output
       // buffering is "stackable" so we don't even have to
       // worry about previous or encompassing buffering.
       ob_start&#40;&#41;;
       phpinfo&#40;8&#41;;
       $module_info = ob_get_contents&#40;&#41;;
       ob_end_clean&#40;&#41;;
       if &#40;preg_match&#40;"/bgds+versionb&#91;^dnr&#93;+?&#40;&#91;d.&#93;+&#41;/i",
               $module_info,$matches&#41;&#41; &#123;
           $gd_version_number = $matches&#91;1&#93;;
       &#125; else &#123;
           $gd_version_number = 0;
       &#125;
   &#125;
   return $gd_version_number;
&#125;
 
return;
[url]http://www.photographybykevin.net[/url]

Simple Viewer FAQ By Kevin
[url]http://knguyentu.com/wordpress/photography-by-kevin/simpleviewer-flash-photo-gallery/[/url]