#!/usr/local/bin/perl
# derived from ~/bin/lisa2html.p by David MacKay (c) 1999
#
# album.p creates a page by page linked album of pictures (see also gallery.p)
#
# example usage :
# ls -flisa image1.jpg image2.gif | album.p title="Lecture notes" file=L1
#
# this creates a master file called L1.html which points to the other files
#
# ls -flisa (files) | album.p title="Holiday" path="pics/" file=file parent="http://www.inference.phy.cam.ac.uk/mackay/" parenttext="Back to my Home Page" addressstring="
(c) David MacKay"
#
# The "parent" arguments modify the footer in the main page.
#
# also, like lisa2html,
# creates an html document which lists the files and their sizes
#
# $path is prepended to all image names only.
#
# David J.C. MacKay (c) 1997,1999
# does not make its own thumbs!
# foreach f ( *jpg )
# foreach? convert $f -geometry 32x32 thumb/$f
# FI is the main file
# IF is the current image file.
use Image::Size;
use Image::Size 'html_imgsize';
$border=1 ;
$includefirstlink = 1 ;
$includealternatepdf = 0 ; # whether to add links to pdf files with same names
$footalso = 0 ; # whether the foot has the previous/next thing also
$labels = 0 ; # whether a label file is supplied, and if so, its name
$parent = 0 ; # change to "http://www.inference.phy.cam.ac.uk/teaching/dynamics/"
# to get this URL inserted in the main page.
$parent = "http://www.inference.phy.cam.ac.uk/teaching/dynamics/notes.html" ;
$parenttext = "Back to Dynamics Page" ;
$addressstring = "
\nDavid MacKay <mackay\@mrao.cam.ac.uk>\n";
$punc = "----" ;
$title = "Album by D. MacKay" ;
$suppresssuffix = 0 ; # whether to modify the name printed
$subdots = 0 ; # whether to modify the name printed
$thumbs = 0 ; # whether to include the images themselves in the main page.
$thumbpath = "thumb/" ;
$table = 0 ; # whether to put in a table form.
$file = "index" ;
$path="";
$colors='BGCOLOR="#FFFFEE" TEXT="#000000" LINK="#0000C8" ALINK="#C80000"
VLINK="#C80000"' ;
# How to override with command line
eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift;
$Head1 = "\n$title\n\n\n" ;
$Head2 = "\n
\n" ;
if ($table) {
$Head2 .= "\n" ;
} else {
$Head2 .= "\n" ;
}
$head1 = "\n$title\n\n" ;
$head2 = "\n | \n" ;
#if ($table ) {
# $foot .= "
\n" ;
#} else {
# $foot .= "\n" ;
#}
$foot2 = "\n" ;
$foot = $parent ? "
$parenttext \n" : "" ;
#
# Other users should put their personal footer here.
#
$foot = $footstring . $foot . $addressstring ;
$foot .= "\n\n \n" ;
if ($labels) { open ( LA, "< $labels" ) ; }
# start printing the main file
open ( FI , "> $file.html" ) ;
print FI $Head1.$title.$Head2 ;
$index = "| Up to Index |" ;
$imagenumber ++ ;
$nextname = "$file.$imagenumber.html" ;
$imagenumber -- ;
if ($includefirstlink) {
print FI " | See the first image |
\n" ;
}
while ( <> ) {
s/^\s*// ;
if ( ! (/^total/) ) {
@a = split ;
# if this is sunos, then we have:
# 0num, 1size, 2permis, 3n, 4owner, 5size, 6dat, 7dat, 8dat, 9file
# under linux,
# 478191 57 -rw-r--r-- 1 mackay other 57992 Apr 25 21:40 grab1.jpg
# 0 1 2 3 4 5 6size 7dat 8 9time 10file
if ($#a > 9) {
$name = $a[10] ;
print STDERR "l" ;
} else {
$name = $a[9] ;
print STDERR "s" ;
}
if ($labels) {
$label = ;
} else { $label = "" ; }
$imagenumber ++ ;
if ( $imagenumber > 1 ) {
$oldname = $thisname ;
}
$thisname = "$file.$imagenumber.html" ;
$imagenumber ++ ; $nextname = "$file.$imagenumber.html" ;
$imagenumber -- ;
print STDERR " opening $thisname\n" ;
system ( "rm -f $thisname" ) ;
open ( IF , "> $thisname" ) ;
print IF $head1.$name.$head2 ;
print IF " $label | " ;
$name =~ s/\*// ; # remove executable tag
$size = html_imgsize("$name");
if (!$table ) {
print FI " " ;
} else {
print FI "" ;
}
$printname = $name ;
if ($suppresssuffix) {
$printname =~ s/\.jpg// ;
$printname =~ s/\.gif// ;
}
if ($subdots) {
$printname =~ s/\./ / ;
}
if ( $thumbs ) {
$tsize = html_imgsize("$thumbpath$path$name");
print FI "" ;
if($table) { print FI " | " ;}
}
$pdfstring = "" ; $gifstring = "" ;
if ($includealternatepdf) {
$pdfstring = " / pdf file" ;
$pdfstring =~ s/\.(jpg|gif)/.pdf/ ;
$gifstring=$1 ;
}
print FI "$printname $punc $gifstring($a[1]K)$pdfstring:$label " ;
if ($table ) {
print FI " |
" ;
} else {
print FI "\n" ;
}
# print FI "
\n" ;
print FI "\n" ;
$headstring = "" ;
if ( $imagenumber > 1 ) {
$headstring .= "| Previous | " ;
}
$headstring .= " | Next Image |\n$index" ;
print IF $headstring ;
print IF "\n
\n" ;
print IF "" ;
if ($footalso) {
print IF "\n
\n" ;
print IF $headstring ;
}
print IF "\n" ; #
print IF $footstring ; # this appears in index and all pages, eg copyright string
print IF $foot2 ;
}
}
if ($table ) {
print FI "\n" ;
} else {
print FI "\n" ;
}
print FI $foot ;
$command = "rm -f $nextname; ln -s $file.html $nextname\n" ;
system ($command) ;
print STDERR "\n" ;