#!/usr/bin/perl
=pod
NAME
make-html
Make html files using images in subdirectories of
USAGE
make-html
INPUT
-- root directory of image files
OUTPUT
The output of this routine is html files that present all of the
images in . The html files are contained in
/html/.
OPTIONS
-a annotate photos by modifying .txt files
VARIABLES
$cd --
$dir --
$dir35 --
$dir50 --
$dir70 --
$dirtxt --
$dirfull --
$html --
$title_txt --
$title --
$name_txt --
$name --
$number --
$ext1,2,3,4 -- "jpg";
$ext2="JPG"; $ext3="jpeg"; $ext4="JPEG";
$files -- `/bin/ls -1 $dir/*.jpg`; chomp $files;
@files -- split "\s*\n",$files;
$filem -- $file; $filem =~ s/^s//; $filem =~ s/.jpg$//;
$file35 -- "$filem\_$dir35";
$file50 -- "$filem\_$dir50";
$file70 -- "$filem\_$dir70";
$filefull -- $filem;
$tmp -- `/bin/ls $filem.$ext1 $filem.$ext2 $filem.$ext3 $filem.$ext4`;
@tmp --
$basename --
$dirname --
$ext --
$txt -- FileRead("$dirtxt/$filem.txt");
$head -- FileRead("$dirtxt/$filem.head");
$sample --
SUBROUTINES
FileRead -- read input file; return contents in a string variable
FileWrite -- write string variable to file
NOTES
Run create-images-for-html before this routine.
AUTHOR
Written Feb 16, 2002 by Joe Werne
=cut
use File::Basename;
use File::Copy;
use strict;
my($number);
my($title);
my($name);
my($filem);
my($file35);
my($file50);
my($file70);
my($filefull);
my($filel);
my($file35l);
my($file50l);
my($file70l);
my($filefulll);
my($filer);
my($file35r);
my($file50r);
my($file70r);
my($filefullr);
my($tmp);
my(@tmp);
my($basename);
my($dirname);
my($ext);
my($extl);
my($extr);
my($txt);
my($head);
my($i);
my($file);
my($line);
my($files);
my(@files);
my(@ls);
my($sample);
my(@args);
my(@opts);
my($anon);
my($pid);
# separate options and arguments on the command line
@opts = grep /^-/,@ARGV;
@args = grep !/^-/,@ARGV;
# define variable $anon used to decide if we should annotate images
$anon = grep /^\-a/,@opts;
# read cd directory name
if ($#args != 0) { die "USAGE: make-html [-a] \n" }
my($cd) = $args[0];
# define icon directory name
my($icons) = "icons";
# define icons to use
my($left_arrow) = "$ENV{HOME}/icons/arrows/arrw18bwcd.gif";
my($right_arrow) = "$ENV{HOME}/icons/arrows/arrw18bwdd.gif";
# define permissions mode for directory creation
my($mode) = 0755;
# define directory name to use as filename guide
my($dir) = "s";
# define directory where 35% images reside
my($dir35) = "35";
# define directory where 50% images reside
my($dir50) = "50";
# define directory where 70% images reside
my($dir70) = "70";
# define directory where text for images resides
my($dirtxt) = "txt";
# define directory where full images reside
my($dirfull) = "images";
# define directory where html files will reside
my($html) = "html";
if (! -d "$cd/$html") { mkdir "$cd/$html",$mode }
# define directory where scripts will reside
my($scripts) = "scripts";
if (! -d "$cd/$scripts")
{
mkdir "$cd/$scripts",$mode ;
($basename, $dirname, $ext) = fileparse($0,'\..*'); $ext=~s/\.//;
@ls = `/bin/ls $dirname`;
foreach $file (@ls)
{
chomp $file;
copy "$dirname/$file","$cd/$scripts";
}
}
# define image file extensions
my($ext1)="jpg"; my($ext2)="JPG"; my($ext3)="jpeg"; my($ext4)="JPEG";
chdir "$cd";
# define the file to contain the title for the main web page
my($title_txt) = "$dirtxt/title";
# define the file to contain the name of the main web page
my($name_txt) = "$dirtxt/name";
# define the file to contain a list of sample images to appear
# on the main html page
my($sample_txt) = "$dirtxt/sample";
# get the number of images
@ls=`/bin/ls $dirfull/*.$ext1 $dirfull/*.$ext2 $dirfull/*.$ext3 $dirfull/*.$ext4`;
$number = $#ls + 1;
$number = " ($number-image album)";
print "\$number=$number\n";
# get the title to appear on the main web page
if (-e $title_txt)
{
$title = FileRead("$title_txt"); chomp $title;
$title = "$title";
}
else
{
print "Please input the title you would like to appear on the main web page\n";
$title = UserInput(); chomp $title;
$title = FileWrite("$title_txt","$title");
}
# get the title of the main web page
if (-e $name_txt)
{
$name = FileRead("$name_txt"); chomp $name;
}
else
{
print "Please input the file name you would like to use for the main web page\n";
$name = UserInput(); chomp $name;
$name = FileWrite("$name_txt","$name");
}
# make sure a sample file exists
if (! -e $sample_txt)
{
print "Please provide a list of sample images to appear on the main web page\n";
print "(Just hit return if you don't want to specify sample images now.)\n";
$sample = UserInput(); chomp $sample;
# if uesr entered nothing, select first image in $dir="s" as sample
if ($sample =~ /^$/)
{
@ls = `/bin/ls "$dir"`;
$sample = $ls[0]; chomp $sample;
$sample = "s/$sample";
}
# write sample file
$sample = FileWrite("$sample_txt","$sample");
}
# get a list of .jpg files in $dir ($dir="s")
my($ext1)="jpg"; my($ext2)="JPG"; my($ext3)="jpeg"; my($ext4)="JPEG";
$files = `/bin/ls -1 $dir/*.jpg`; chomp $files;
print "\$files=$files\n";
$files =~ s/$dir\///g;
@files = split "\s*\n",$files;
my($file_1) = $files[0];
my($filem_1) = $file_1; $filem_1 =~ s/^s//; $filem_1 =~ s/.jpg$//;
my($file35_1) = "$filem_1\_$dir35";
my($file50_1) = "$filem_1\_$dir50";
my($file70_1) = "$filem_1\_$dir70";
my($filefull_1) = $filem_1;
my($file_N) = $files[$#files];
my($filem_N) = $file_N; $filem_N =~ s/^s//; $filem_N =~ s/.jpg$//;
my($file35_N) = "$filem_N\_$dir35";
my($file50_N) = "$filem_N\_$dir50";
my($file70_N) = "$filem_N\_$dir70";
my($filefull_N) = $filem_N;
@files = ($file_N,@files,$file_1);
# Create and fill directory for icons
if (! -d "../$icons") {mkdir "../$icons",$mode}
# Copy arrow icons from ~/icons/arrows
($basename, $dirname, $ext) = fileparse($right_arrow,'\..*'); $ext=~s/\.//;
copy "$right_arrow","../$icons/right_arrow.$ext";
$right_arrow = "right_arrow.$ext";
($basename, $dirname, $ext) = fileparse($left_arrow,'\..*'); $ext=~s/\.//;
copy "$left_arrow","../$icons/left_arrow.$ext";
$left_arrow = "../icons/left_arrow.$ext";
#-------------------------------------------------------------
# HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML
#-------------------------------------------------------------
# write header for $html/$name.html
open (TO,">$html/$name.html") or die "Could not open $html/$name.html\n";
print TO < $title$number
here_0
#-------------------------------------------------------------
# create an entry in $html/$name.html for each .jpg file
for ( $i=1 ; $i<$#files ; $i++ )
{
# strip off leading "s" and trailing .jpg and store in $filem
$filel = $files[$i-1]; $filel =~ s/^s//; $filel =~ s/.jpg$//;
$filem = $files[$i] ; $filem =~ s/^s//; $filem =~ s/.jpg$//;
$filer = $files[$i+1]; $filer =~ s/^s//; $filer =~ s/.jpg$//;
# create $file35 variable
$file35l = "$filel\_$dir35";
$file35 = "$filem\_$dir35";
$file35r = "$filer\_$dir35";
# create $file50 variable
$file50l = "$filel\_$dir50";
$file50 = "$filem\_$dir50";
$file50r = "$filer\_$dir50";
# create $file70 variable
$file70l = "$filel\_$dir70";
$file70 = "$filem\_$dir70";
$file70r = "$filer\_$dir70";
# create $filefull variable
$filefulll = $filel;
$filefull = $filem;
$filefullr = $filer;
# get $filefull extension
chdir $dirfull;
$tmp = `/bin/ls $filem.$ext1 $filem.$ext2 $filem.$ext3 $filem.$ext4`;
chomp $tmp; @tmp=split /\n/,$tmp; $tmp=$tmp[0];
($basename, $dirname, $ext) = fileparse($tmp,'\..*'); $ext=~s/\.//;
$tmp = `/bin/ls $filel.$ext1 $filel.$ext2 $filel.$ext3 $filel.$ext4`;
chomp $tmp; @tmp=split /\n/,$tmp; $tmp=$tmp[0];
($basename, $dirname, $extl) = fileparse($tmp,'\..*'); $extl=~s/\.//;
$tmp = `/bin/ls $filer.$ext1 $filer.$ext2 $filer.$ext3 $filer.$ext4`;
chomp $tmp; @tmp=split /\n/,$tmp; $tmp=$tmp[0];
($basename, $dirname, $extr) = fileparse($tmp,'\..*'); $extr=~s/\.//;
chdir "../";
# edit image captions if $anon >= 1
if ($anon >= 1)
{
$pid = fork;
if ($pid == 0) { `display "$dir35/$file35.jpg"`; }
else {`emacs "$dirtxt/$filem.txt"`; wait; }
}
# read text and head for $filem
$txt = FileRead("$dirtxt/$filem.txt");
$head = FileRead("$dirtxt/$filem.head");
print "../$dir/s${filem}.jpg\n";
#-------------------------------------------------------------
# HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML
#-------------------------------------------------------------
# create an entry in $html/$name.html for each .jpg file
print TO <
here_1
#-------------------------------------------------------------
#-------------------------------------------------------------
# HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML
#-------------------------------------------------------------
# create an html file for a 35% image
open (TOH,">$html/$file35.html") or die "Could not open $html/$file35.html\n";
print TOH < $file35.jpg
here_3
#-------------------------------------------------------------
close TOH;
#-------------------------------------------------------------
# HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML
#-------------------------------------------------------------
# create a photo album html file for a 35% image
open (TOH,">$html/${file35}album.html") or die "Could not open $html/${file35}album.html\n";
print TOH < $file35.jpg
|
$txt |
here_3a
#-------------------------------------------------------------
close TOH;
#-------------------------------------------------------------
# HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML
#-------------------------------------------------------------
# create an html file for a 50% image
open (TOH2,">$html/$file50.html") or die "Could not open $html/$file50.html\n";
print TOH2 < $file50.jpg
here_4
#-------------------------------------------------------------
close TOH2;
#-------------------------------------------------------------
# HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML
#-------------------------------------------------------------
# create a photo album html file for a 50% image
open (TOH2,">$html/${file50}album.html") or die "Could not open $html/${file50}album.html\n";
print TOH2 < $file50.jpg
|
$txt |
here_4a
#-------------------------------------------------------------
close TOH2;
#-------------------------------------------------------------
# HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML
#-------------------------------------------------------------
# create an html file for a 70% image
open (TOH2,">$html/$file70.html") or die "Could not open $html/$file70.html\n";
print TOH2 < $file70.jpg
here_5
#-------------------------------------------------------------
close TOH2;
#-------------------------------------------------------------
# HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML
#-------------------------------------------------------------
# create a photo album html file for a 70% image
open (TOH2,">$html/${file70}album.html") or die "Could not open $html/${file70}album.html\n";
print TOH2 < $file70.jpg
|
$txt |
here_5a
#-------------------------------------------------------------
close TOH2;
#-------------------------------------------------------------
# HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML
#-------------------------------------------------------------
# create an html file for full image
open (TOH3,">$html/$filefull.html") or die "Could not open $html/$filefull.html\n";
print TOH3 < $filefull.$ext
Click picture to return to 70%-resolution image.
here_6
#-------------------------------------------------------------
close TOH3;
}
#-------------------------------------------------------------
# HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML HTML
#-------------------------------------------------------------
# write trailing information for $html/$name.html
print TO <
Click here for more pictures.
Click here for the album.
here_2
#-------------------------------------------------------------
close TO;
#============================================================== FileRead
sub FileRead{
#-------------------------------------------------- Read input variables
my ($file,$ctd,$line);
$file = $_[0]; $ctd = "";
#------------------------------------------------------------- Open file
open (FILE,"<$file") or die "Could not open $file\n";
#---------------------------------------------------- Read file contents
while (){
chomp $_; $line = "$_\n"; $ctd = $ctd.$line
}
#------------------------------------------------------------ Close file
close (FILE);
#----------------------------------------------- Return contents in $ctd
return $ctd
}
#============================================================= FileWrite
sub FileWrite{
#-------------------------------------------------- Read input variables
my ($file,$ctd,$suffix);
$file=$_[0]; $ctd=$_[1]; $suffix=$_[2]; $ctd="$ctd$suffix";
#------------------------------------------------------------- Open file
open (FILE,">$file") or die "Could not open $file\n";
#---------------------------------------------------- Read file contents
print FILE $ctd;
#------------------------------------------------------------ Close file
close (FILE);
#----------------------------------------------- Return contents in $ctd
return $ctd
}
#============================================================= UserInput
sub UserInput{
#-------------------------------------------------- Read input variables
my ($ctd) = "";
#-------------------------------------------- Get input string from user
$ctd = readline(*STDIN); chomp $ctd;
#----------------------------------------------- Return contents in $ctd
return $ctd
}
__END__