#!/usr/local/bin/perl -w
# derived from ~/bin/lisa2html.p by David MacKay (c) 1999
#
# album.p creates a page by page linked album of pictures
# gallery.p derived from album.p april 2000
# This automatically makes microimages for the front page
#
# example usage : no longer valid
# ls -flisa image1.jpg image2.gif | gallery.p title="Lecture notes" file=L1
#
# this creates a master file called L1.html which points to the other files
#
# The "parent" arguments modify the footer in the main page.
# $path is prepended to all image names only.
#
# David J.C. MacKay (c) 1997,1999
# FI is the main file
# IF is the current image file.
## old!!
# ls -flisa *jpg | gallery.p file=index title="Shah Products" parent="../../" parenttext="Shah Industries" thumbs=1 table=1 suppresssuffix=1 subdots=1
## new:
# gallery.p file=photos title="Bandana pictures" parent="" parenttext="Bandana 2001" thumbs=1 creationneeded=1 table=1 suppresssuffix=1 subdots=1 labels=labels minargs=2 headfontoptions="" navigate=1 includebacktoindexlink=1 selfcontained=1
use Image::Size;
use Image::Size 'html_imgsize';
$headfontoptions="size=1";
$minargs = 3 ; # how many items should be in each row of the label file
$footinheadtoo = 1 ; # whether the main index has the foot text at the top too.
# options for the convert programme when making thumb
$thumboptions = " -enhance -equalize -normalize -contrast " ;
$thumboptions = " -enhance -equalize -normalize " ; # equalize is terrible for ordinary pictures but for thumbs seems quite good
$thumboptions = " -equalize " ; # actually, for recent scans, it was horrible
$thumboptions = " -normalize " ;
$navigate_at_end = 0 ; # placement in the image files of the navigator in the head
$footstring = "" ; #
$labelsyntax = 1;
$labelsep = "-" ;
$includemasterlink = 1 ;
$includebacktoindexlink = 0 ;
$creationneeded = 1 ;
$selfcontained = 0 ; # whether the toplevel page has
etc
# set to 0 if incorporating this page into some other html page
# set to 1 for standalone pages
$includeimagenames = 1 ;
$includerawimagelinks = 0 ;
$navigate = 0 ; # whether to include "forward and backward" navigators in the pages
$tossfilename = 1 ;
$thumbborder=1;
$preservethumb = 1 ;
$thumbgeom= "50x40" ;
$verbose = 0 ;
$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";
$addressasparent = 0 ;
$punc = "" ;
$title = "Album by D. MacKay" ;
$suppresssuffix = 0 ; # whether to modify the name printed
$subdots = 0 ; # whether to modify the name printed by removing the "." from
$thumbs = 0 ; # whether to include the images themselves in the main page.
$thumbpath = "thumb/" ;
$table = 0 ; # whether to put in a table form.
$tableoptions = "border=0 cellpadding=0 cellspacing=4" ;
$file = "index" ;
$path="";
$colors='BGCOLOR="#FFFFEE" TEXT="#000000" LINK="#0000C8" ALINK="#C80000"
VLINK="#C80000"' ;
$indexisremote = 1 ;
$includeparentinindex = 0 ;
# How to override with command line
eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift;
$minargs -- ;
if ($indexisremote) {
$originalthumbpath = $thumbpath ;
$htmlpath=$path ; # this is prepended onto the html names
$thumbpath = "$path$thumbpath" ; # thumbs have to be dangly
$path = "" ; # but once we are in the dangled document we don't need paths
}
if($creationneeded && $thumbs) {
$thumbpath2 = $originalthumbpath ;
$thumbpath2 =~ s#/$## ;
$exists = (-e $thumbpath2 ) ;
if( ! $exists) {
print STDERR "making directory $thumbpath2\n" ;
$command = "mkdir $thumbpath2" ;
system $command ;
}
}
if ($selfcontained) {
$Head1 = "\n$title\n\n\n" ;
} else {
$Head1 = "\n" ;
}
$Head2a = "\n
\n" ;
$Head2 = "\n" ;
if ($table) {
$Head2 .= "
\n" ;
} else {
$Head2 .= "\n" ;
}
$head1 = "\n$title\n\n" ;
$head1a = " \n" ;
$head1b = "
\n" ;
$head2a = "\n\n" ;
$head2b = "\n\n" ;
$head3a = "\n\n" ;
$head3b = "\n\n" ;
#if ($table ) {
# $foot .= "
\n" ;
#} else {
# $foot .= "\n" ;
#}
$foot2 = "\n" ;
$footcontents = "$parenttext \n" ;
$foot = ($parent && $includeparentinindex) ? "
$footcontents" : "" ;
if ( $addressasparent ) {
$addressstring = $footcontents ;
}
#
# Other users should put their personal footer here.
#
if($selfcontained) {
$foot = $foot . $addressstring ;
$foot .= "\n\n \n" ;
}
if ($labels) { open ( LA, "< $labels" ) ; }
else { print STDERR "the labels variable must be set \n";
exit(0) ;
}
# start printing the main file
open ( FI , "> $file.html" ) ;
print FI $Head1.$title.$Head2a ;
if ($footinheadtoo) { print FI "$footcontents\n" ; }
print FI $Head2 ;
$index = "| Back to Index |" ;
LALOOP: while ( ) {
s/^\s*// ;
$label = $_ ;
@a = split ;
if ($#a < $minargs ) { next LALOOP ; }
$name = $a[0] ;
$size = html_imgsize("$name");
# print STDERR "size is $size \n" ;
$label =~ s/$name// if ($tossfilename) ; # get rid of filename from label!
print STDERR "here is the label: $label\n" if ($verbose) ;
if ($labelsyntax) {
@labelparts = split( '\\\\' , $label ) ;
$mainlabel = $labelparts[0] ;
print STDERR $mainlabel,"\n" if ($verbose) ;
print $labelparts[1] , "\n" if ($verbose) ;
} else {
$mainlabel = $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" ) ;
$name =~ s/\*// ; # remove executable tag
if (!$table ) {
print FI " " ;
} else {
print FI "" ;
}
if ($labels ) {
$printname = $mainlabel ;
} else { # turn image name into a title
$printname = $name ;
if ($suppresssuffix) {
$printname =~ s/\.jpg// ;
$printname =~ s/\.gif// ;
}
if ($subdots) {
$printname =~ s/\./ / ;
}
}
# remove leading and trailing space
$printname =~ s/^\s+// ;
$printname =~ s/\s+$// ;
$headstring = "" ;
if ($navigate) {
if ( $imagenumber > 1 ) {
$headstring .= "| Previous | " ;
}
$headstring .= " | Next Image |\n" ;
}
if ($includebacktoindexlink) {
$headstring .= "$index" ;
}
if ($includemasterlink) {
$headstring .= " ".$footcontents." |" ; # eg "back to home page"
# the foot was created elsewhere using parent
# ." " ;
}
# print the IMAGE file
print IF $head1 ;
if (!$navigate_at_end) { print IF $head1a ;
print IF $headstring."\n" ;
print IF $head1b ;
}
if ($includeimagenames) {
print IF $head1a ;
print IF $printname ;
print IF $head1b ;
}
if ($labels && $labelsyntax) {
for($ii=1;$ii<=$#labelparts;$ii++) {
if ($ii<=1) { print IF $head2a ; } else { print IF $head3a ; }
print IF " $labelparts[$ii] $labelsep " ;
if ($ii<=1) { print IF $head2b ; }else { print IF $head3b ; }
}
}
if ( $thumbs ) {
if ($creationneeded) {
# the idea here is to check if a thumb has already been made.
$thisfilename = "$originalthumbpath$name" ;
$exists = -f $thisfilename ? 1 : 0 ;
# $command = "$exists = -f $thisfilename ? 1 : 0 " ;
# eval($command) ;
if($preservethumb && $exists) {
print STDERR "$originalthumbpath$name exists\n" if $verbose;
} else {
$command = "convert $thumboptions -geometry $thumbgeom $name $originalthumbpath$name" ;
print STDERR "doing $command \n" ;
system $command ;
}
}
$thumbsize = html_imgsize("$originalthumbpath$name");
# print STDERR "thumbsize is $thumbsize\n" ;
print FI " " ;
if($table) { print FI " | " ;}
}
print FI "$printname" ;
if ($labels && $labelsyntax) {
for($ii=1;$ii<=$#labelparts;$ii++) {
print FI " | $labelparts[$ii] " ;
}
}
if ($includerawimagelinks) {
print FI " $punc($a[1]K):";
}
if ($table ) {
print FI " |
" ;
}
else {
# print FI "\n" ;
}
# print FI "
\n" ;
print FI "\n" ;
if ($navigate_at_end) { print IF $headstring ; }
print IF "\n
\n" ;
print IF "
" ;
print IF "\n" ; #
print IF $footstring ; #
if ($footalso) {
print IF "\n
\n" ;
print IF $headstring ;
}
print IF $foot2 ;
}
if ($table ) {
print FI "\n" ;
} else {
print FI "\n" ;
}
print FI $foot ;
if($navigate) { #
$command = "rm -f $nextname; ln -s $file.html $nextname\n" ;
system ($command) ;
}
print STDERR "\n" ;