From 81b599ccac172f1a42a3fed65ea2338cc3328bf0 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 11 Sep 2010 15:23:58 +0200 Subject: archive support --- bin/gen-xhtml-thumbnails | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/bin/gen-xhtml-thumbnails b/bin/gen-xhtml-thumbnails index d93ac3e..c037b16 100755 --- a/bin/gen-xhtml-thumbnails +++ b/bin/gen-xhtml-thumbnails @@ -3,12 +3,17 @@ # License: WTFPL use strict; use warnings; -use Image::Imlib2; -use Getopt::Long; + use constant { DEFAULT_FILEMODE => oct(644), }; +use Archive::Tar; +use Cwd; +use Getopt::Long; +use Image::Imlib2; + + my $directory = '.'; my $thumbdir = "$directory/.thumbs"; my $indexfile = "$directory/index.xhtml"; @@ -22,6 +27,8 @@ my $css_source; my ($dx, $dy); my @files; my $number = 0; +my $create_archive = 0; +my $tar = Archive::Tar->new(); local $| = 1; sub print_progress { @@ -43,6 +50,7 @@ GetOptions( 'n|show-name' => \$thumb_show_names, 't|title=s' => \$title, 'q|quality=i' => \$thumb_quality, + 'x|archive' => \$create_archive, ); if (@ARGV > 0) { @@ -81,9 +89,16 @@ foreach my $file (readdir($dirhandle)) { closedir($dirhandle); +@files = sort { lc($a) cmp lc($b) } @files; + +if ($create_archive) { + print "Adding files to tar archive\n"; + $tar->add_files(@files); +} + print "Generating thumbnails [ - cached | + generated ]\n"; -foreach my $file (sort { lc($a) cmp lc($b) } @files) { +foreach my $file (@files) { my $thumb; if (defined($css_source)) { @@ -151,6 +166,13 @@ foreach my $file (sort { lc($a) cmp lc($b) } @files) { } print "\n"; +if ($create_archive) { + print "Writing tar archive to disk\n"; + $tar->write('images.tar', undef, (split(qr{/}, getcwd))[-1]); + + print $index "
archive\n"; +} + print $index <<'EOD';
-- cgit v1.2.3