Topic: Modification of buildgallery.php

I was poking around a modified the buildgallery.php a bit. Now all you need is just a copy of buildgallery.php in each gallery you have. No need to edit the buildgallery.php to put in your absolute or relative path, as it will detect the URL of where the buildgallery is located and assume the images and thumbs path are directly below it.

here is a sample code...

// SET GALLERY OPTIONS HERE
// -----------------------
// Set Gallery options by editing this text:
//
//
//
// -----------------------------------------------------------------------------
// START MODIFICATION BY K. NGUYEN-TU JUNE 2006
// USAGE: COPY BUILDGALLERY.PHP TO GALLERY PATH
// SET PERMISSION TO 755
// POINT URL TO BUILDGALLERY.PHP TO CREATE XML FILE
// EXAMPLE: HTTP://WWW.DOMAIN.COM/PICTURES/GALLERY1/BUILDGALLERY.PHP
//------------------------------------------------------------------------------

// set global carriage return sign
$carreturn = "rn";
$pattern = '/&#40;<&#40;?&#58;&#91;^<>&#93;+&#40;?&#58;"&#91;^"&#93;*"|'&#91;^'&#93;*'&#41;?&#41;+>&#41;/';

// 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 = str_replace &#40;'/buildgallery.php', '', $url_string&#41;; //Truncate buildgallery.php from URL


// $linkpath = image path & $thumbpath = thumbnail path
$linkpath = $url_string."/images/"; // sample http&#58;//www.domain.com/pictures/gallery1/images/
$thumbpath = $url_string."/thumbs/"; // sample http&#58;//www.domain.com/pictures/gallery1/thumbs/

// Misc Settings&#58; Set Text Color, Frame Color, Frame Color, Border Size, Rows, Columns, etc.,
$textcolor = "0xFFFFFF";
$framecolor = "0xFFFFFF";
$bgcolor = "0x181818";
$framewidth = "3";
$stagepadding = "0";
$thumbnailcolumns = "2"; // How many columns for thumbnails
$thumbnailrows = "6"; // How many rows for thumbnails
$navposition = "right"; // Thumbnails position &#40;right, left, top, bottom&#41;
$gallery_title = "Misc Pictures"; //Name of Gallery
$showDownloadLinks = true; // Show Download Links &#40;True, False&#41;

// Obtain Absolute Path To buildgallery.php
//$absolute_path = getcwd&#40;&#41;;
//$absolute_path = str_replace &#40; chr &#40; 92 &#41;, '/', $absolute_path &#41;;


$options .= '<SIMPLEVIEWER_DATA maxImageDimension="700" textColor="'.$textcolor.'" frameColor="'.$framecolor.'" bgColor="'.$bgcolor.'" frameWidth="'.$framewidth.'" stagePadding="'.$stagepadding.'" thumbnailColumns="'.$thumbnailcolumns.'" thumbnailRows="'.$thumbnailrows.'" navPosition="'.$navposition.'" navDirection="LTR" title="'.$gallery_title.'" imagePath="'.$linkpath.'" thumbPath="'.$thumbpath.'">';
// Set showDownloadLinks to true if you want to show a 'Download Image' link as the caption to each image.

// END MODIFICATION BY K. NGUYEN-TU JUNE 2006

// END OF OPTIONS
// -----------------------
[url]http://www.photographybykevin.net[/url]

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

Re: Modification of buildgallery.php

I got tired copying the buildgallery.php into each gallery I have and having to execute it each gallery individually. So I modified it a bit

IF have more than one gallery, place the buildgallery.php in one directory below those gallery.

For example:

Main picture path is "./pictures/"

and all your individual gallery are located under pictures

"./pictures/lasvegas/"
"./pictures/hollywood/"

etc...

place the buildgallery.php in the ./pictures/

it will look for all directories under the pictures location, and create the XML file for you (given you have an IMAGES and THUMBS directory under each of these subdirectories)




<?
// -----------------------
// 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
// -----------------------

$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;;
    &#125;
  &#125;
&#125;
closedir&#40;$dirfolder&#41;;


// 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 = 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 = "3";
$stagepadding = "0";
$thumbnailcolumns = "2"; // How many columns for thumbnails
$thumbnailrows = "6"; // How many rows for thumbnails
$navposition = "right"; // Thumbnails position &#40;right, left, top, bottom&#41;
$gallery_title = "Misc Pictures"; //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 maxImageDimension="700" textColor="'.$textcolor.'" frameColor="'.$framecolor.'" bgColor="'.$bgcolor.'" frameWidth="'.$framewidth.'" stagePadding="'.$stagepadding.'" thumbnailColumns="'.$thumbnailcolumns.'" thumbnailRows="'.$thumbnailrows.'" navPosition="'.$navposition.'" navDirection="LTR" title="'.$gallery_title.'" 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;
     //add auto captions&#58; 'Image X'
     if &#40;$showDownloadLinks&#41;&#123;        
        $xml .= '<CAPTION><!&#91;CDATA&#91;<A href="'.$linkpath.''.$key.'" target="_blank" class="mainlevel1"><center><b><U>OPEN LARGER IMAGE&#58;<br>'.$key.'</U></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."/imageData.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  = 45;
    $outputY  = 45;
    $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]

Re: Modification of buildgallery.php

smilepak, thats awesome.

A couple questions though. What happens if the XML/thumbnail images already exist?  Does it overwrite/delete them?

I'm afraid of trying this before I know if it's been thoroughly tested.  My problem is that I used the original buildgallery.php file and for some reason it did not insert values for imagePath and thumbPath into my XML files for some reason...