#!/lusr/bin/perl #---------------------------------------------------------------------------- # Wed Sep 23 20:38:44 CDT 1998 (width and height of thumbnail are specifiable) # Wed Aug 26 00:55:11 CDT 1998 (added more comments, fixed minor bug) # Sun Jun 21 01:32:02 CDT 1998 # # thumb : generate html pages with any number of images (gif, jpg, etc) # for easier, thumbnailed view, will navigation buttons # # usage: thumb [-n ] [-t ] [-x <x>] [-y <y>] # <n> : number of images per page. # <title> : title string (also serves as the filename prefix) # <x> : width of each thumbnail - defaults to 50 # <y> : width of each thumbnail - defaults to 50 # # input: run thumb in the directory with the images. # # output: several html pages, starting with view0.html, view1.html.... # If you gave the title option, it will be used as the # file prefix. # # Source URL: # # http://www.cs.utexas.edu/users/yschoe/src/thumb # # Requirements: # # Must be on a UN*X platform (or it should have ls, wc, awk). # Perl Version 5.003 or better # * may work with older versions, but I cannot tell for sure. # # Pitfalls, restrictions, and TIPS # # This is a coarse hack to help managing your image files # easier on a LOCAL SYSTEM. The thumbnail images are not # smaller, generated-on-the-fly images -- they are the # actual images that the web browser downloads in full # and then resizes it according to the HTML tag, so # if you have 10MB worth of images, the web page generated # by this script will download the full 10MB when displaying # the thumbnails. # # However, if you intend to use only one image on a page, # and have a way of navigating between different pages, # (such as presentation slides) you can use this script # # Naturally, this script is not recommended for use # as a CGI script. # # Yoonsuck Choe # yschoe@cs.utexas.edu # # Freely Distributable. No warranty. #---------------------------------------------------------------------------- # Generate thumbnail html file : section into 20 images per page # generates as many html files as necessary require "getopts.pl"; &Getopts('n:t:x:y:h'); if ($opt_h) { print <<EOF ; usage: thumb -n <n> -t <title> [-h] <n> : number of images per page. <title> : title string (and filename) -h : for help EOF exit 0; } if ($opt_t) { $title = $opt_t; } else { $title = "view"; } if ($opt_n) { $perpage = $opt_n; } else { $perpage = 30; } if ($opt_x) { $geomx = $opt_x; } else { $geomx = 50; } if ($opt_y) { $geomy = $opt_y; } else { $geomy = 50; } print "images per page = $perpage\n"; $count=0; $nofiles="`/bin/ls | /bin/wc | /bin/awk '{print $1}'`"; # get file listing @files = `/bin/ls`; $fcount = $#files+1; $pagecount = int($fcount/$perpage); if ($fcount%$perpage==0) { $pagecount --; } print $pagecount+1; print " pages generated\n"; $curpage = 0; for ($i=0; $i<= $#files; $i++) { # print header $previous = ($curpage==0)?0:$curpage-1; $next = $curpage+1; if ($i%$perpage==0) { if ($i!=0) { &navigation($previous,$curpage,$next,$pagecount); close(VFILE); $curpage ++; $previous = ($curpage==0)?0:$curpage-1; $next = $curpage+1; } open(VFILE,"> $title$curpage.html"); print VFILE "<title> $title$curpage \n"; print VFILE ""; print VFILE "

$title$curpage

\n"; &navigation($previous,$curpage,$next,$pagecount); print VFILE "

\n"; } chop $files[$i]; print VFILE "\n\t\n" ; } # for the last page &navigation($previous,$curpage,$next,$pagecount); close(VFILE); print "Files = $fcount\n"; # End of program #---------------------------------------------------------------------------- # Subroutine : print navigation buttons #---------------------------------------------------------------------------- sub navigation { local ($previous,$curpage,$next,$pagecount) = @_; print VFILE "

"; print VFILE "
\n"; if ($curpage != 0) { print VFILE "[Previous<\/a>] "; } if ($next <= $pagecount) { print VFILE "[Next<\/a>] "; } for ($j=0; $j<=$pagecount; $j++) { if ($j == $curpage) { print VFILE ""; print VFILE "[$j] "; print VFILE ""; } else { print VFILE "[$j<\/a>] "; } } print VFILE "
\n"; }