Evan McNabb's Homepage
Home | Blog | About Me | Linux / Open Source Software | Photo Album | Funny Stuff | Misc Stuff
#!/usr/bin/php 
<?php

/*

   Copyright (C) 2003 Evan McNabb

   enmAlbum is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   enmAlbum is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   For a copy of the GNU General Public License go to http://www.gnu.org/licenses/gpl.html
   or write to:
         Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

*/

/*
*  Evan's new and improved photo album page creator:
*     Pass it a directory (on the command line) and it will resize the images using
*     the linux command 'convert'; it will then create a simple webpage based off of these
*     modified images. After you're done you can go through the page and add your own comments. 
*     This program is customized to how I like it; you'll want to tweak it for your needs.
*/

if ($argv[1] == null)
{
        die(
"Correct usage: enmAlbum directoryname\n");
}

// Most of my pages are shtml; you might want to change this to a plain html file
$indexhtml_filename "$argv[1]/index.shtml";
$indexhtml_filehandle fopen$indexhtml_filename"w" );

// Use CSS and write HTML headers
fwrite$indexhtml_filehandle"<style> \n
                div.picture \n
                { \n
                    width: 200px; \n
                    height: 200px; \n
                    padding: 5px; \n
                    border: 1px solid black; \n
                    background: #f2f2f2; \n
                } \n
                </style>
                \n" 
);
fwrite$indexhtml_filehandle"<!--Add page title here--> <title></title>\n\n" );
fwrite$indexhtml_filehandle"<html>\n<body>\n\n" );
fwrite$indexhtml_filehandle"<!--Add page header here--> <h1></h1>\n\n" );
fwrite$indexhtml_filehandle"<center>Click on the picture to enlarge</center>\n\n" );

// Get a file listing
$ls_output = `ls $argv[1]`;
$ls_output_array split"\n"$ls_output );

// Create a new row every certain number of pictures
$picture_counter 0;

fwrite$indexhtml_filehandle'<center><table cellspacing="0" cellpadding="5" border="0">' );

echo 
"<tr>\n";
fwrite$indexhtml_filehandle"<tr>\n" );
foreach ( 
$ls_output_array as $filename )
{
    
// In my case, the high res pictures that come from my digital camera end in .JPG; I only want to convert those pictures
    
if ( $filename != null && strstr$filename".JPG" ) ) 
        {
        
// The pictures straight out of my camera are huge; I want to resize them and also make a thumbnail
        
echo "Converting $filename to $filename-normal.jpg and $filename-thumbnail.jpg...\n";
        
$convert_output = `convert -size 700x700 -resize 700x700 $argv[1]/$filename $argv[1]/$filename-normal.jpg`;
        
$convert_thumbnail_output = `convert -size 150x150 -resize 150x150 $argv[1]/$filename $argv[1]/$filename-thumbnail.jpg`;
        
        
// Increment the count
        
if ( $picture_counter == 
        {
            echo 
"</tr>\n<tr>\n";
            
fwrite$indexhtml_filehandle"</tr>\n<tr>\n" );
            
$picture_counter 0;
        }
        
$picture_counter++;

        
fwrite$indexhtml_filehandle'<td><div class="picture">' );
        
fwrite$indexhtml_filehandle"<center><a href=\"$filename" "-normal.jpg" "\"><img src=\"$filename-thumbnail.jpg\" border=\"0\"></a></center>\n" );
        
fwrite$indexhtml_filehandle"<!--Insert comment below -->\n <center><p></p></center>\n\n" );
        
fwrite$indexhtml_filehandle'</div></td>' );

    } 
    else
    {
        echo 
"Skipping $filename\n";
    }
}
echo 
"</tr>\n";
fwrite$indexhtml_filehandle"</tr>\n" );
fwrite$indexhtml_filehandle"</table></center>\n" );

fwrite$indexhtml_filehandle"</html>\n</body>\n\n" );

fclose$indexhtml_filehandle );

?>