#!/usr/bin/perl -w use strict; use Getopt::Std; use File::stat; # Get command line parameters my %opts; getopts('hxTb:f:t:s:n:c:o:', \%opts); # If no argument given, exit with an error if( @ARGV < 1 || $opts{'h'} ) { print "[ERROR] Usage: image_list.pl [options] ... \n"; print " -t Sets page title\n"; print " -n <num> Sets number of thumbnails per page (default infinite)\n"; print " -c <columns> Sets number of thumbnails per line (default 3)\n"; print " -s <size> Sets thumbnail size (e.g. 127x127)\n"; print " -o <dir> Sets the output directory (default .)\n"; print " -b <color> Choose background color\n"; print " -f <color> Choose foreground color\n"; print " -x Do not generate thumbnails\n"; print " -T Generate only the thumbnails\n"; print " -h Show usage (this help)\n"; exit(1); } # Print credits print "HTML Image List Generator\n"; print "Written By Giovanni Beltrame - 2003\n\n"; # Set defaults and parse command line parameters my $size = "127x127"; my $n = 0; my $columns = 3; my $title = "Pictures"; my $outdir = "./"; my $thumbs = 0; my $bg = 'FFFFFF'; my $fg = '000000'; $title = $opts{'t'} if $opts{'t'}; $size = $opts{'s'} if $opts{'s'}; $n = $opts{'n'} if $opts{'n'}; $columns = $opts{'c'} if $opts{'c'}; $outdir = $opts{'o'} if $opts{'o'}; $bg = $opts{'b'} if $opts{'b'}; $fg = $opts{'f'} if $opts{'f'}; $thumbs = 1 if !$opts{'x'}; # Strip leading slashes to get file names my @files = @ARGV; for (@files) { s,/+$,,; s,.*/,,; } # Check if thumbnail directory exists, otherwise create one system "mkdir $outdir" . "/thumbs" if( !( -e "./thumbs") ); # Get image list and generate thumbnails # Default size il 127x127 my $i=0; if( $thumbs ) { print "Generating thumbnails...\n"; while( $i < @ARGV ) { print "Image $files[$i]..."; system "convert -size $size $ARGV[$i] -resize $size +profile \"*\" $outdir" . "/thumbs/$files[$i]\n"; print "done!\n"; $i++; } exit(0) if $opts{'T'}; } print "Generating HTML..."; open(OUT, "> pics.html"); print OUT <<HTML; <html> <head> <title>$title

$title

HTML my $sb; my $j = 0; my $k = 0; $i = 0; while ( $i < @ARGV ) { print OUT "\n" if ( $k%$columns == 0); $sb = stat( $ARGV[$i] ); print OUT " \n"; $i++; $k++; print OUT "\n" if ( $k%$columns == 0); if( $n > 0 && $i%$n == 0 && $i < @ARGV ) { print OUT "

\n"; print OUT " File: $files[$i]
\n"; print OUT " Size: ". $sb->size() ."b

\n"; print OUT "Prev \n" if ( $j > 1) ; print OUT "Prev \n" if ( $j == 1) ; print OUT "Next

\n" if( $i < @ARGV); print OUT "\n"; close( OUT ); $j++; open(OUT, "> pics$j.html"); print "[$j]"; print OUT < $title

$title - page $j

HTML $k = 0; } } if( $j > 0 ) { print OUT "

\n"; print OUT "Prev

\n"; print OUT "\n"; } else { print OUT "\n\n"; } close( OUT ); print "...done!\n";