#!/usr/bin/perl -w #thumbnail_webpage.pl #version 1.2 #Copyright 2003-2005 John C. Vernaleo #Unfortunately, I am not comfortable putting unobscured email addresses #on the web, but these shouldn't be too hard to figure out. # # (my_first_name)@netpurgatory.com # or # (my_last_name)@astro.umd.edu # # This program 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. # # This program 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. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # See readme_thumbnails.txt for more information and a copy of the GPL my $main_dir=$ARGV[0]; unless(defined($main_dir)){ print "Type directory name with pictures: "; chomp($main_dir=); } chdir $main_dir or die "Cannot change to $main_dir $!"; print "now in $main_dir\n"; #Need this to take care of main_dir my @dirs; my @tmp2=glob "*"; my $tmp2; my $haspic=0; foreach $tmp2 (@tmp2) { if(($tmp2=~".jpg")||($tmp2=~".JPG")||($tmp2=~".jpeg")||($tmp2=~".JPEG")||($tmp2=~".png")) { $haspic=1; } } if($haspic) { push(@dirs,"./"); &mkthumbs; } #this finds sub directories &get_dir(); open MAINPAGE, ">pictures_main.html" or die "cannot open pictures_main.html $!"; select MAINPAGE; &page_top; print "Listing of Pictures\n"; print "\n\n"; print "

Listing of Picture Thumbnails

\n"; print "

\n"; print "\n"; foreach $_ (@dirs) { print "'."$_\n"; print "
\n"; } print "

\n\n"; close MAINPAGE; #Subroutines sub get_dir{ my ($base)=(@_); my $base2; my @tmp=glob "*"; my @tmp2; my $tmp2; my $haspic; foreach (@tmp) { $haspic=0; if((-d $_)&&($_ ne "pages")&&($_ ne "thumbs")) { chdir $_ or die "Cannot change to $_ $!"; if($base) { $base2=$base."/$_"; }else{ $base2=$_; } @tmp2=glob "*"; foreach $tmp2 (@tmp2) { if(($tmp2=~".jpg")||($tmp2=~".JPG")||($tmp2=~".jpeg")||($tmp2=~".JPEG")||($tmp2=~".png")) { $haspic=1; } } if($haspic) { push(@dirs,$base2); &mkthumbs; } &get_dir($base2); chdir ".."; } } } sub mkthumbs{ my @jpg=glob "*.jpg"; my @jpg2=glob "*.JPG"; my @gif=glob "*.gif"; my @gif2=glob "*.GIF"; my @png=glob "*.png"; my @png2=glob "*.PNG"; my @pics; push(@pics,@jpg); push(@pics,@jpg2); push(@pics,@gif); push(@pics,@gif2); push(@pics,@png); push(@pics,@png2); unless (-e "thumbs"){ mkdir "thumbs" or die "Can't make directory: $!"; } unless (-e "pages"){ mkdir "pages" or die "Can't make directory: $!"; } foreach $file (@pics) { my $command="convert -size 120x120 $file -resize 120x120 +profile ".'"*"'." thumbs/thum_".$file; unless (-e "thumbs/thum_$file"){ system $command; } } open WEBPAGE, ">pages/pictures.html" or die "Cannot create file: $!"; select WEBPAGE; &page_top; print "\n"; &body(@pics); close WEBPAGE; } sub page_top{ print "\n"; print ''."\n"; print ''."\n"; print "\n"; } sub body{ my (@pics)=(@_); my $i; my $file; print "Pictures\n"; print "\n\n"; print "

\n"; for($i=0;$i<=$#pics;$i++) { $file=$pics[$i]; select WEBPAGE; print ''; print ''.$file.''; print "\n"; #make individual picture page open PAGE, ">pages/".($i+1).".html" or die "Cannot create file: $!"; select PAGE; &page_top; print "Picture ".($i+1)." of ".($#pics+1)."\n"; print "\n\n

\n"; print ''.$file.''."\n
\n"; if(($i==0)||($i==$#pics)){ if($i==0){ print 'Next Picture'."\n"; } if($i==$#pics){ print 'Previous Picture'."\n"; } } else{ print 'Previous Picture'."\n"; print 'Next Picture'."\n"; } print "

\n\n"; close PAGE; } select WEBPAGE; print "

\n\n"; }