From f872ca47b0b1d72d5780058f98534774f07b89d0 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 4 Aug 2011 09:41:37 +0200 Subject: add options to change template and thgumbnail size Signed-off-by: Florian Pritz --- generate_gallery.pl | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/generate_gallery.pl b/generate_gallery.pl index 6f68cd5..0d3996c 100755 --- a/generate_gallery.pl +++ b/generate_gallery.pl @@ -14,7 +14,11 @@ my $templatedir = abs_path(dirname($0))."/generate_gallery.d"; my $startdir = cwd(); my %opts = (); -GetOptions(\%opts, "exif|e", "verbose|v", "help|h", "filenamedesc") or pod2usage(2); + +$opts{template} = "$templatedir/template.html"; +$opts{thumbnailsize} = 200; + +GetOptions(\%opts, "exif|e", "verbose|v", "help|h", "filenamedesc", "template=s", "thumbnailsize|s=i", "htmlonly") or pod2usage(2); pod2usage(0) if $opts{help}; pod2usage(-verbose => 0) if (@ARGV== 0); @@ -23,6 +27,12 @@ if ($opts{exif}) { load Image::ExifTool, "ImageInfo"; }; +$opts{template} = abs_path($opts{template}); +unless (-r $opts{template}) { + print STDERR "Error: template file not readable: $!\n"; + exit 1; +} + for my $dir (@ARGV) { chdir $startdir; unless (-d $dir) { @@ -45,7 +55,7 @@ for my $dir (@ARGV) { print "processing $dir/$file ...\n"; my $img = new Image::Magick; $img->Read("$abs_dir/$file"); - $img->Thumbnail(geometry=>"200x200"); + $img->Thumbnail(geometry=>$opts{thumbnailsize}."x".$opts{thumbnailsize}); $img->Write("$abs_dir/thumbs/$file"); } @@ -67,7 +77,7 @@ for my $dir (@ARGV) { $html .= "\"\"\n"; $html .= "\n\n"; } - open TEMPLATE, "<", "$templatedir/template.html"; + open TEMPLATE, "<", "$opts{template}"; open OUTPUT, ">", "$abs_dir/index.html"; while (