#!/usr/bin/perl # # adapted from a script by Bob Hain, 11/30/99 # # # default values # $outfile = "new.index.html"; # # process arguments # $use_large = 1; while ( $arg = shift @ARGV ) { if ( $arg eq "--large" ) { $use_large = 1; } if ( $arg eq "--outfile" ) { $outfile = shift @ARGV; } } # # Generate all images # $src = "Source"; $ldir = "Large"; $sdir = "Small"; $mdir = "Movies"; $columns = 3; $swidth = 170; $sheight = 128; $lwidth = 1024; $lheight = 768; # # Make sure directories exist # if ( ! -e $ldir ) { mkdir $ldir, 0755; } if ( ! -e $sdir ) { mkdir $sdir, 0755; } # return 1 if file1 is newer than rile2 sub is_newer { my($file1, $file2) = @_; # print " - $file1 - $file2 - \n"; ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime1, $ctime, $blksize, $blocks) = stat($file1); ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size, $atime, $mtime2, $ctime, $blksize, $blocks) = stat($file2); if ( $mtime1 > $mtime2 ) { return 1; } else { return 0; } } # # Make images (both large and small) # @FILES = `ls $src/*.jpg $src/*.JPG $src/*.png`; foreach $file ( @FILES ) { chop $file; $file =~ s/$src\///; if ( is_newer( "$src/$file", "$ldir/$file" ) || ! -e "$ldir/$file" ) { print "Updating $ldir/$file\n"; system("cp -f $src/$file $ldir"); system("mogrify -geometry \'$lwidth" . "X" . "$lheight>\' -interlace LINE -quality 80 $ldir/$file"); } if ( is_newer( "$ldir/$file", "$sdir/$file" ) || ! -e "$sdir/$file" ) { print "Updating $sdir/$file\n"; system("cp -f $ldir/$file $sdir"); system("mogrify -geometry \'$swidth" . "X" . "$sheight>\' -interlace LINE -quality 80 $sdir/$file"); } } # # Check for large and small images to remove # @FILES = `ls $ldir`; foreach $file ( @FILES ) { chop($file); # print "$file\n"; if ( ! -f "$src/$file" ) { print "No matching src file - deleting large image $file ...\n"; unlink( "$ldir/$file" ); } } @FILES = `ls $sdir`; foreach $file ( @FILES ) { chop($file); if ( ! -f "$src/$file" ) { print "No matching src file - deleting small image $file ...\n"; unlink( "$sdir/$file" ); } } # # Build image list (for next/previous/first/last links) # open( MASTER, " ) { chop; if ( m/\.jpg$/ || m/\.JPG$/ || m/\.png$/ ) { push @imagelist, $_; } else { # just ignore everything else } } close( MASTER ); # # Prepair $link subdirectory # $link = "Link"; system("rm -rf $link"); mkdir $link, 0755; # # Assemble index.html # $dir = `pwd`; chop($dir); $title = `basename $dir`; chop($title); open( MASTER, "$outfile" ); $j = 1; $in_table = 0; while ( ) { chop; if ( m/^#/ ) { # ignore comments } elsif ( m/\.txt$/ ) { # insert text if ( $in_table ) { $in_table = 0; print OUT "\n"; print OUT "\n"; } $file = $_; open( IN, "<$src/$file" ); while ( ) { print OUT $_; } close( IN ); print OUT "

\n"; $j = 1; $in_table = 0; } elsif ( m/\.jpg$/ || m/\.JPG$/ || m/\.png$/ ) { # insert image in 3 wide tables $in_table = 1; $file = $_; $i = `basename $file`; chop($i); if ( $j == 1 ) { print OUT "\n"; print OUT "\n"; print OUT "\n"; } if ( $i =~ m/\.jpg$/ ) { $linkname = `basename $i .jpg`; } elsif ( $i =~ m/\.JPG$/ ) { $linkname = `basename $i .JPG`; } elsif ($i =~ m/\.png$/ ) { $linkname = `basename $i .png`; } chop($linkname); # print OUT "\n"; if ( $j == $columns ) { $in_table = 0; print OUT "\n"; print OUT "
\n"; print OUT "\n"; $thumbinfo = `identify $sdir/$i`; ($name, $type, $geom, $junk) = split(/\s+/, $thumbinfo, 4); ($twidth, $theight) = split(/x/, $geom); $theight =~ s/\+.*$//; print OUT ""; print OUT "\"$linkname\""; print OUT "
\n"; if ( -f "$src/$linkname.txt" ) { print OUT "\n"; open( IN, "<$src/$linkname.txt" ); while ( ) { print OUT $_; } close( IN ); print OUT "\n"; } else { print OUT "\n"; print OUT "$linkname\n"; print OUT "\n"; } print OUT "
\n"; } if ( ++$j > $columns ) { $j = 1; } } elsif ( m/\.AVI$/ || m/\.mpg$/ || m/\.mov$/ ) { # insert image in 3 wide tables $in_table = 1; $file = $_; $i = `basename $file`; chop($i); if ( $j == 1 ) { print OUT "\n"; print OUT "\n"; print OUT "\n"; } if ( $i =~ m/\.AVI$/ ) { $linkname = `basename $i .AVI`; } elsif ( $i =~ m/\.mpg$/ ) { $linkname = `basename $i .mpg`; } elsif ( $i =~ m/\.mov$/ ) { $linkname = `basename $i .mov`; } else { die "unknown movie type\n"; } chop($linkname); # print OUT "\n"; if ( $j == $columns ) { $in_table = 0; print OUT "\n"; print OUT "
\n"; print OUT "\n"; $thumbinfo = `identify $mdir/$linkname.jpg`; ($name, $type, $geom, $junk) = split(/\s+/, $thumbinfo, 4); $geom =~ s/\+.*//; ($twidth, $theight) = split(/x/, $geom); print "movie thumb geom = $geom $twidth $theight\n"; print OUT ""; if ( -f "$mdir/$linkname.jpg" ) { print OUT "\"$linkname\""; } else { print OUT "$linkname"; } print OUT "\n"; if ( -f "$mdir/$linkname.txt" ) { print OUT "
\n"; print OUT "\n"; open( IN, "<$mdir/$linkname.txt" ); while ( ) { print OUT $_; } close( IN ); print OUT "\n"; } else { print OUT "
\n"; print OUT "\n"; print OUT "$linkname\n"; print OUT "\n"; } print OUT "
\n"; } if ( ++$j > $columns ) { $j = 1; } } else { # just pass along the rest as is $j = 1; if ( $in_table ) { $in_table = 0; print OUT "\n"; print OUT "\n"; } print OUT "$_\n"; } } # # Generate Links # # @FILES = `ls $src/*.jpg $src/*.JPG $src/*.png`; $first = $imagelist[0]; if ( $first =~ m/\.jpg$/ ) { # print " ext = jpg\n"; $firstname = `basename $first .jpg`; } elsif ( $first =~ m/\.JPG$/ ) { # print " ext = JPG\n"; $firstname = `basename $first .JPG`; } else { # print " ext = png\n"; $firstname = `basename $first .png`; } chop($firstname); $last = $imagelist[$#imagelist]; if ( $last =~ m/\.jpg$/ ) { # print " ext = jpg\n"; $lastname = `basename $last .jpg`; } elsif ( $last =~ m/\.JPG$/ ) { # print " ext = JPG\n"; $lastname = `basename $last .JPG`; } else { # print " ext = png\n"; $lastname = `basename $last .png`; } chop($lastname); for ($i = 0; $i <= $#imagelist; $i++) { $file = $imagelist[$i]; # print "'$file'\n"; if ( $i > 0 ) { $prev = $imagelist[$i - 1]; } else { $prev = "null"; } if ( $i < $#imagelist ) { $next = $imagelist[$i + 1]; } else { $next = "null"; } if ( $file =~ m/\.jpg$/ ) { $linkname = `basename $file .jpg`; $ext = "jpg"; } elsif ( $file =~ m/\.JPG$/ ) { $linkname = `basename $file .JPG`; $ext = "JPG"; } else { $linkname = `basename $file .png`; $ext = "png"; } chop($linkname); $nice_name = $linkname; $nice_name =~ s/\_/ /g; if ( $prev =~ m/\.jpg$/ ) { # print " ext = jpg\n"; $prevname = `basename $prev .jpg`; } elsif ( $prev =~ m/\.JPG$/ ) { # print " ext = JPG\n"; $prevname = `basename $prev .JPG`; } else { # print " ext = png\n"; $prevname = `basename $prev .png`; } chop($prevname); if ( $next =~ m/\.jpg$/ ) { $nextname = `basename $next .jpg`; } elsif ( $next =~ m/\.JPG$/ ) { $nextname = `basename $next .JPG`; } else { $nextname = `basename $next .png`; } chop($nextname); $outfile = "$link/$linkname.html"; open( OUT, ">$outfile" ); print OUT < $linkname.$ext [First] EOF if ( $prevname ne "null" ) { print OUT "[Previous]\n"; } else { print OUT "[Previous]\n"; } if ( $nextname ne "null" ) { print OUT "[Next]\n"; } else { print OUT "[Next]\n"; } print OUT <[Last]
$nice_name
EOF if ( -f "$src/$linkname.txt" ) { # print OUT "
\n"; open( IN, "<$src/$linkname.txt" ); while ( ) { print OUT $_; } close( IN ); } print OUT <
Click on the image for the full size version.
EOF if ( $use_large ) { print OUT " \n"; } else { print OUT " \n"; } print OUT <
EOF close( OUT ); }