Project:

Enhancements to the Silvemine photo viewer

 

As per the author's web site "Silvermine(tm) is an easy to configure photoalbum PHP script. It enables you to browse and view pictures in your favorite webbrowser in a very intuitive way". Silvermine is written by Maurice ref http://www.ruwebit.net/article/110. Silvermine(tm) is Copyright(c) 2001-2008 by RuweBit/MASE Software Engineering and is free for personal use.

Silvermine requires Apache and PHP as well as a few libraries. I run it on Ubuntu. The last published version was in 2008. This page documents the changes made and to implement the following enhancements:

- The version available from the official web site uses the depricated EREG which I have replaced with reg_match.

- Silvermine can generate the thumbnails on the fly which is really cool but slow, it can also create the thumbnails and save them in the same directory as the origianal. I have made enhancements so that Silvermine saves the thumbnails in a different directory, which stops the original directory getting clogged up with thumbnail images, and also restricts Silvermine php write permissions to a dedicated directory.

- I use Silvermine inside other web pages by calling it as a Server Side Include (SSI) to display the thumbnails from specificed directory, a good example is http://www.kingtech.com.au/giddyup/201005-HandoverTrip/ where I call Silvermine to create and place the thumbnails from nearly 10 different directories. Which makes this more about a usage example for Silvermine.

I have sent these modifications to the author so perhaps they may get included in the published version.
Contents:

I believe I have captured the prerequisites in the steps below but to start with it has to be a computer running Linux. At present I use Ubuntu which this has been tested on, but before that it worked on Redhat. 

For the installation I wanted:

- my photos in a separate directory that Silvermine and apache2 can not change.

- I want as much of the Silvermine executables and libraries in a separate directory away from everything else leaving only the bare minimum additional files in the directory with my photos.

- I want the thumbnails created and saved in a separate directory away from my photos and nothing else in the directory because everyone will need to have write access to it.

 

In this installation example I have two photo directories, one is a standard Silvermine use example, and the other uses Silvermine as a Server Side Include into an existing web page.

Directory:

Required permissions:

Purpose:

/var/www

Usually the default apache permissions

This is the directory for the Apache web page

/var/www/silvermine

Usually the default apache permissions

This is a new directory that has all the Silvermine scripts.

/var/www/photos

 Anybody must be able to read the files and execute the directories

This is the Directory where the original photos are put by the user, including any sub directories the user might like to have.

/var/www/giddyup/trip/day1

/var/www/giddyup/trip/day2

 Anybody must be able to read the files and execute the directories

This is another Directory where the user puts their photos, only a web page uses Silvermine as an Apache Server Side Include to view them.

/var/www/tempForCGI-BIN

Anybody can read. write, and execute the directoty.

This is used by apache and Silvermine only. It is a read writeable directory where Silvermnine creates directories and thumbnail images and apache can read the files and send to browsers.

This is new in Version 2.6.2 B



Step 1: Create the directories using the above owners and permissions.

sudo mkdir /var/wwwsilvermine

sudo mkdir /var/www/giddyup

sudo mkdir /var/www/giddyup/trip

sudo mkdir /var/www/giddyup/trip/day1

sudo mkdir /var/www/giddyup/trip/day2

sudo find /var/www/ -type d -exec chmod a+xr {} \;

sudo find /var/www/ -type f -exec chmod a+r {} \;

sudo mkdir /var/www/tempForCGI-BIN

sudo chmod 777 /var/www/tempForCGI-BIN

sudo chown nobody:www-data /var/www/tempForCGI-BIN

Step 2: First you need a working apache2 web site that supports PHP5

sudo apt-get install apache2 php5 libapache2-mod-php5

This may already be done via the previous step, tell apache2 to enable the php5 module using the following command:

sudo a2enmod php5

Silvermine uses PHP GD image library to create the thumbnails. So to install GD support for PHP I found I only needed to

sudo apt-get install php5-gd

libjpeg-progs is used to convert to/from jpeg

sudo apt-get install libjpeg-progs

Step 3: Download version 2.62 from http://www.ruwebit.net/article/110

You should have a file silvermone262.tar.gz

Unzip the files in the right location. Needs to be were the web server can get to them.

sudo mkdir /var/www/silvermine

sudo mv silvermone262.tar.gz /var/www/silvermine

sudo tar -xvzf silvermine262.tar.gz

Step 4 Changes need to silvermine.inc.php

In vi type the following to turn on the line numbering to make it easy to find the lines to change

<esc>:set number

sudo vi silvermine.inc.php

Add to the bottom of line 19
* Author: Maurice de Bijl
Add
* Changed by Stephen Kingham

Add the following new lines starting after line 123
* 2.62 20080503 Several important fixes in watermarking and configuration file
Add
* Beta 20110912 If thumb or normal images created on the hard disk then there is now an option to have these created
* in a separate folder rather than in the same folder as the images.



Change line 145-147 from
$progname = "<a href=\"http://www.ruwebit.net/article/110/\">SilverMine</a>(tm)";
$version = "2.62";
$copyright = "Copyright (c) 2001-2008 <a href=\"http://www.ruwebit.net/\">Ruwebit</a>";

To
$progname = "<a href=\"http://www.kingtech.com.au/projects/silvermine/\">Kingtech Modified SilverMine</a>(tm)";
$version = "2.62beta1";
$copyright = "Copyright (c) 2001-2008 <a href=\"http://www.ruwebit.net/\">Ruwebit</a>";

Change line 244 from
$bIsValid = ereg("^(/|([A-Za-z0-9_.,-~@()=#% ]+/))*$", $strPathName);
To
$bIsValid = preg_match("/^(\/|([A-Za-z0-9_.,-~@()=#% ]+\/))*$/", $strPathName);

Fix spelling, change line 252
// Check if there are no raltive paths (no /./ and no /../ and no /.,/)
To
// Check if there are no relative paths (no /./ and no /../ and no /.,/)

Change line 254
$bRelativePathPresent= ereg("(/[.,]+/)|([.,]+/)|(/[.,]+)]*", $strPathName);
To
$bRelativePathPresent= preg_match("/(\/[.,]+\/)|([.,]+\/)|(\/[.,]+)]*/", $strPathName);

Change line 264
$bUrlPresent = ereg("^([a-zA-Z]+://.*)$", $strPathName);
To
$bUrlPresent = preg_match("/^([a-zA-Z]+:\/\/.*)$/", $strPathName);

Change line 276
$bIsValid = ereg( XXXX
To
$bIsValid = preg_match("/^([A-Za-z0-9_.,-~@()=#% ]+)*$/", $strFileName);

Change Line 286 from
$bUrlPresent = ereg("^([a-zA-Z]+://.*)$", $strFileName);
To
$bUrlPresent = preg_match("/^([a-zA-Z]+:\/\/.*)$/", $strFileName);

Change line 296
$bIsValid = ereg("[A-Za-z]+", $strAction);
To
$bIsValid = preg_match("/[A-Za-z]+/", $strAction);

Change line 306
return ereg("^[0-9]+$", $strString);
To
return preg_match("/^[0-9]+$/", $strString);

After line 377
$strBodyText .= " Pictures URL=".$pictures_url."\n";
Add
$strBodyText .= " Thumb dir=".$thumb_dir."\n";
$strBodyText .= " Thumb URL=".$thumb_url."\n";

Note that the indenting is not quite right starting on line 569, indent as you see fit through to line 602.

And again indenting is not quite right starting on line 618, indent as you see fit through to line 638.

After (line 648)
Global $album;
Add
Global $thumb_dir;
Global $thumb_url;

After line 658
warnings_off();
Add (including a blank line at the beginning)

//
// In the event that the thumb or normal image is being created in a different
// folder to the pictures folder we check that the destination directory exists
// and create it if it doesn't
//
if ( ($thumb_dir != "" ) and ($thumb_url != "" ))
{
// We only create the directories
mkdir ( $thumb_dir.$album, 0777, TRUE);
}

Change line 673
if (is_writable($pictures_dir.$album))
To
if (is_writable($thumb_dir.$album))

Add after (line 685/686)
$image_type = $jpg;
}
Add these lines
if (($strExt == "png") || ($strExt == "PNG"))
{
$image_type = $png;
}
if (($strExt == "gif") || ($strExt == "GIF"))
{
$image_type = $gif;
}

Uncomment 707 through to 710
else if ($image_type == $png)
{
$hSource_image = imagecreatefrompng($strSourceImage);
}


Change line 749 From
$bSucceeded = imagegif($hTarget_image, $strTargetImage); // not supported ??
To
$bSucceeded = imagegif($hTarget_image, $strTargetImage);


After line 749/750
$bSucceeded = imagegif($hTarget_image, $strTargetImage);
}

Add
else if ($image_type == $png)
{
$bSucceeded = imagepng($hTarget_image, $strTargetImage);
}


After line 784
global $pictures_url;
Add
global $thumb_dir;
global $thumb_url;


Before line

//

um art (jpg or gif)

Add

// 0. Show album art if Folder.jpg exists

if ($generate_thumbnail_images == 1 && $thumb_dir != "" && file_exists($thumb_dir.$album.$AlbumsArray[$i]."/".$thumb_prefix."

"))

argin-bottom: 0cm"> {

$strImageName = $thumb_url.$album.$AlbumsArray[$i]."/".$thumb_prefix."Folder.jp

}


Change line 869 from

if (file_exists($pictures_dir.$album.$AlbumsArray[$i]."/".$thumb_prefix.&

jpg"))

To

else if (file_exists($pictures_dir.$album.$AlbumsArray[$i]."/".$thumb_prefix.&

jpg"))


Change line 959 and 960
$strThumbFile = $pictures_dir.$album.$thumb_prefix.$AllFilesArray[$i];
$strThumbUrl = $album.$thumb_prefix.$AllFilesArray[$i];

To
$strThumbFile = $thumb_dir.$album.$thumb_prefix.$AllFilesArray[$i];
$strThumbUrl = $thumb_url.$album.$thumb_prefix.$AllFilesArray[$i];



Change line 961
$strThumbUrl = GetTopUrl($strThumbUrl).$strThumbUrl;
To:
if ( ($thumb_dir == "" ) and ($thumb_url == "" ))
{
$strThumbUrl = GetTopUrl($strThumbUrl).$strThumbUrl;
}

Change line 988
if (file_exists($pictures_dir.$album.$normal_prefix.$strFilename))
To
if (file_exists($thumb_dir.$album.$normal_prefix.$strFilename))

Change line 990
$strSourceImage = $pictures_dir.$album.$normal_prefix.$strFilename
To
$strSourceImage = $thumb_dir.$album.$normal_prefix.$strFilename;

After line 1110
global $album;
Add
global $thumb_dir;
global $thumb_url;

Change lines 1145
if (file_exists($pictures_dir.$album.$normal_prefix.$PicturesArray[$picture]))
To:
if (file_exists($thumb_dir.$album.$normal_prefix.$PicturesArray[$picture]))

Change lines 1147 from
$strPictureURL = $album.$normal_prefix.$PicturesArray[$picture];
To
$strPictureURL = $thumb_url.$album.$normal_prefix.$PicturesArray[$picture];


Change line 1150 From
$strPictureFile = $pictures_dir.$album.$normal_prefix.$PicturesArray[$picture];
To
$strPictureFile = $thumb_dir.$album.$normal_prefix.$PicturesArray[$picture];

Change line 1175 From
$pictures_dir.$album.$normal_prefix.$PicturesArray[$picture],
To
$thumb_dir.$album.$normal_prefix.$PicturesArray[$picture],

Change line 1179
$strPictureURL = $album.$normal_prefix.$PicturesArray[$picture];
To:
$strPictureURL = $thumb_url.$album.$normal_prefix.$PicturesArray[$picture];

Change line 1180 From:
$strPictureURL = GetTopUrl($strPictureURL ).$strPictureURL;
To:
if ( ($thumb_dir == "" ) and ($thumb_url == "" ))
{
$strPictureURL = GetTopUrl($strPictureURL ).$strPictureURL;
}

Change line 1184
$strPictureFile = $pictures_dir.$album.$normal_prefix.$PicturesArray[$picture];
To
$strPictureFile = $thumb_dir.$album.$normal_prefix.$PicturesArray[$picture];

 

Step 5 Changes need to params.inc.php

Need to change params.inc.php to initialise thunb_url and thumb_dir if they are not set.

sudo vi params.inc.php

Change line 53 From
?>
To
//
// Initialise the thumbnail directory and url if it is not set
//
if (!IsSet($thumb_dir)) $thumb_dir = $pictures_dir;
if (!IsSet($thumb_url)) $thumb_url = $pictures_url;
?>



Step 6 Changes need to index.php that comes with silvermine

sudo vi index.php

Change line 3 from
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheet.css\">";
To
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"\silvermine\stylesheet.css\">";

 

Step 7 Changes need to configuration.inc.php

After $generate_normal_images=1 starting at line 233 add these lines, including blank line at beginning:

/**
* If $thumb_dir and $thumb_url are set and
* $generate_normal_images=1 or $generate_thumbs_images=1
* then the thumbs are saved in the $thumb_dir.
* $thumb_url needs to be a URL that point to the above directory (thumb_dir)
*
*/
$thumb_dir="";
$thumb_url="";

Change $webmaster to be your email address.
$webmaster="sysadmin@yourdomain";

Change $silvermine_dir to be the absolute unix path to where the silvermine files were extracted to. In my example it is the following place, well away from everything else in the web site:
$silvermine_dir="/var/www/silvermine/";

Change $pictures_dir to be where silvermine is allowed to look for pictures. This will change between albums.
$pictures_dir="/var/www/photos";

$silvermine_url will be the URL for $silvermine_dir
$silvermine_url= "http://www.yourdomain.com/silvermine/";

$pictures_url is the relative URL from $silvermine_url to point to $pictures_dir and will be different for each album and has to be relative to $silvermine_url.
$pictures_url="http://www.yourdomain.com/photos";

$imagedir is the Unix path to where the Silvermine images that are used for navigation etc, in my example is
$imagedir="/var/www/silvermine/images";

$imageurl is the URL for $imagedir
$imageurl="/silvermine/images/";

Save the small thumbnails on the harddisk
$generate_thumbnail_images=1;

Have decent quality thumbnails:
$thumbnail_image_resolution="240x180";
$thumbnail_image_jpeg_quality=100;

Generate a nice big number of thumbs each time
$max_thumbnail_images_to_generate=20;

Save Normal sized thumbs on the harddisk
$generate_normal_images=1;

$thumb_dir is the absolute Unix path to where the thumb pictures are saved that are created by Silvermine, and $thumb_url is the URL to point to $thumb_dir and it is a good idea to make this unique for each album.
$thumb_dir="/var/www/tempForCGI-BIN/photos/";

Have decent quality larger thumbnails:
$normal_image_resolution="800x600";
$normal_image_jpeg_quality=100;

I turn off navigation depending on the album
$showexifinfo = True;
$albumnavigation = True;
$picturenavigation = True;
$showdescriptions = True;
$showalbums = True;

Do not show the watermark
$addwatermark = False;

 

Step 8 Changes need to apache2

because I wanted silvermine scripts and the thumbnails well away from my web pages I need to tell apache how to find silvermine.

<VirtualHost *:80>
ScriptAlias /cgi-bin/ /var/www/wwwkingtech-cgi-bin/
# tempForCGI is where the CGI programs can write temp files to

Alias /tempForCGI-BIN/ /var/www/tempForCGI-BIN/
Alias /silvermine/ /var/www/silvermine/
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>

 

Usage Example 1.

Copy /var/www/silvermine/index.php /var/www/photos/index.php because I am going to use the silvermine index of the web page. Point your browser to http://yourwebsite/index.php and you should see the photos in /var/www/photos/

Usage Example 2.

I use Silvermine inside other web pages by calling it as a Server Side Include (SSI) to display the thumbnails from specificed directory, a good example is http://www.kingtech.com.au/giddyup/201005-HandoverTrip/ where I call Silvermine to create and place the thumbnails from nearly 10 different directories. So the following is more about a usage example for Silvermine.

This is a more complex example, more about using Service Side Includes in Apache2.

Create a file called silvermine.php with the following contents:

sudo vi /var/www/giddyup/trip/silvermine.php

<?
// Stylesheet
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"/silvermine/stylesheet.css\">";
// Include configuration
Include("configuration.inc.php");
// Include language
Include($silvermine_dir."language_".$language.".inc.php");
// Include silvermine
Include($silvermine_dir."silvermine.inc.php");
?>

Copy /var/www/silvermine/configuration.inc/php /var/www/giddyup/trip/configuration.php

Edit /var/www/giddyup/trip/configuration.php and make these changes

$pictures_dir="/var/www/giddyup/trip/";

// for /var/www/giddyup/trip/configuration.inc.php To turn
// "http://www.yourdomain.com/silvermine/" into "/giddyup/trip/"requires:
$pictures_url=�../giddyup/trip/�;

$thumb_dir="/var/www/tempForCGI-BIN/silvermine/giddyuptrip/�;
$thumb_url="/tempForCGI-BIN/silvermine/giddyuptrip/";

// For /var/www/giddyup/trip/configuration.inc.php Silvermine is

// used as an include in a larger HTML page so I turn off navigation and I do

// not display sub-directories:
$showexifinfo = False;
$albumnavigation = False;
$picturenavigation = True;
$showdescriptions = False;
$showalbums = False;

Enable Server Side Includes

We need to allow SSI (Server Side Includes) in Apache2. Need to edit the apache available site configuration file to include enabling SSI for the particular directory where Silvermine executable are.

Sudo vi /etc/apache2/sites-available/default

<VirtualHost *:80>
# tempForCGI is where the CGI programs can write temp files to
Alias /tempForCGI-BIN/ /var/www/tempForCGI-BIN/
Alias /silvermine/ /var/www/silvermine/
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews +Includes
AllowOverride None
Order allow,deny
allow from all
# XBitHack is needed for includes
XBitHack on
</Directory>
<Directory /var/www/tempForCGI-BIN/>
Options MultiViews
AllowOverride None
# SRK Added:
Order allow,deny
# SRK Added:
Allow from all
</Directory>
</VirtualHost>

 

Restart apache2

sudo /etc/init.d/apache2 restart

Create these directries and put some photos in them

/var/www/giddyup/trip/day1/

/var/www/giddyup/trip/day2/

Create index.html that will use the SSI

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>

<head>
</head>
<body>
Day 1
<!--#include virtual="silvermine.php?album=day1/" -->
Day 2
<!--#include virtual="silvermine.php?album=day2/" -->
</body>
</html>

And that should be that.



Author and copyright

Stephen.Kingham <at> kingtech.com.au

Comments and suggests are welcome