From ac79b62359ecb4ab7e12c7d930460226da9bfbe8 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 27 Feb 2011 16:35:01 +0100 Subject: Change internal --no-names handling --- lib/App/Dthumb.pm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/App/Dthumb.pm b/lib/App/Dthumb.pm index a8014de..1b673c7 100755 --- a/lib/App/Dthumb.pm +++ b/lib/App/Dthumb.pm @@ -24,6 +24,7 @@ sub new { $conf->{size} //= 200; $conf->{spacing} //= 1.1; $conf->{quality} //= 75; + $conf->{names} = !$conf->{'no-names'}; $ref->{config} = $conf; @@ -123,7 +124,7 @@ sub create_thumbnails { sub create_thumbnail_html { my ($self, $file) = @_; my $div_width = $self->{config}->{size} * $self->{config}->{spacing}; - my $div_height = $div_width + ($self->{config}->{no_names} ? 0 : 10); + my $div_height = $div_width + ($self->{config}->{names} ? 10 : 0); $self->{html} .= sprintf( "
\n", @@ -140,7 +141,7 @@ sub create_thumbnail_html { $self->{config}->{dir_thumbs}, ($file) x 2, ); - if (not $self->{config}->{no_names}) { + if ($self->{config}->{names}) { $self->{html} .= sprintf( "\t
\n" . "\t%s\n", -- cgit v1.2.3 From b0cc851a192a87cbaf57758a59a1c6a38797514a Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 27 Feb 2011 16:39:57 +0100 Subject: Update documentation --- Build.PL | 2 +- README | 7 ++++++- bin/dthumb | 12 +----------- lib/App/Dthumb.pm | 2 -- 4 files changed, 8 insertions(+), 15 deletions(-) (limited to 'lib') diff --git a/Build.PL b/Build.PL index 2158460..7cd582c 100644 --- a/Build.PL +++ b/Build.PL @@ -16,11 +16,11 @@ my $build = Module::Build->new( requires => { 'perl' => '5.10.0', 'autodie' => 0, - 'Archive::Tar' => 0, 'Cwd' => 0, 'Data::Section' => 0, 'Getopt::Long' => 0, 'Image::Imlib2' => 0, + 'MIME::Base64' => 0, }, ); $build->create_build_script(); diff --git a/README b/README index 14e0ed6..8678cef 100644 --- a/README +++ b/README @@ -2,7 +2,8 @@ dthumb - Create static HTML thumbnail list for images Requires: * perl version 5.10 or newer - * The Image::Imlib2 perl module + * Data::Section + * Image::Imlib2 Installation: @@ -11,3 +12,7 @@ Installation: > sudo ./Build install You can then run 'man dthumb' for more information. + + +You may also run './Build test'. This will require the Test::More, +Test::Compile and Test::Pod modules. diff --git a/bin/dthumb b/bin/dthumb index 012b911..38e330e 100755 --- a/bin/dthumb +++ b/bin/dthumb @@ -50,13 +50,6 @@ Note that recursion is not yet supported. =over -=item B<-x>, B<--archive> - -Create (and link) an "image.tar" archive containing all full-size image files. -All but the last directories in the files' path are stripped, besides that the -directory structure is preserved. So, if you run dthumb -x in -.../mydir/, the archive will contain mydir/1.jpg, mydir/2.jpg etc. - =item B<-n>, B<--no-names> Do not show image names below thumbnails @@ -94,7 +87,7 @@ None. =item * autodie (Included in core as of perl 5.10.1) -=item * Archive::Tar (subject to change) +=item * Data::Section =item * Image::Imlib2 @@ -104,9 +97,6 @@ None. Thumbnails of changed images are not yet recreated. -When used with B<-x>, the completer tar archive is kept in memory, leading to -enormous memory usage and possibly out-of-memory errors. - =head1 AUTHOR Copyright (C) 2009, 2010 by Daniel Friesel Ederf@chaosdorf.deE diff --git a/lib/App/Dthumb.pm b/lib/App/Dthumb.pm index 1b673c7..f525776 100755 --- a/lib/App/Dthumb.pm +++ b/lib/App/Dthumb.pm @@ -8,7 +8,6 @@ use 5.010; use base 'Exporter'; use App::Dthumb::Data; -use Archive::Tar; use Cwd; use Image::Imlib2; @@ -29,7 +28,6 @@ sub new { $ref->{config} = $conf; $ref->{data} = App::Dthumb::Data->new(); - $ref->{tar} = Archive::Tar->new(); $ref->{html} = $ref->{data}->get('html_start'); -- cgit v1.2.3 From 1647027acdde0c71eda1b781723688f1a53c6076 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 27 Feb 2011 16:51:34 +0100 Subject: Add help/version switches --- bin/dthumb | 3 ++- lib/App/Dthumb.pm | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/bin/dthumb b/bin/dthumb index 38e330e..8c96670 100755 --- a/bin/dthumb +++ b/bin/dthumb @@ -13,11 +13,12 @@ my $opt = {}; GetOptions( $opt, qw{ + help|h size|d=i spacing|s=f no-names|n quality|q=i - archive|x + version|v }, ) or die("Please see perldoc -F $0\n"); diff --git a/lib/App/Dthumb.pm b/lib/App/Dthumb.pm index f525776..f26848f 100755 --- a/lib/App/Dthumb.pm +++ b/lib/App/Dthumb.pm @@ -44,6 +44,7 @@ sub new { sub run { my ($self) = @_; + $self->check_cmd_flags(); $self->read_directories(); $self->create_files(); $self->delete_old_thumbnails(); @@ -51,6 +52,19 @@ sub run { $self->write_out_html(); } +sub check_cmd_flags { + my ($self) = @_; + + if ($self->{config}->{version}) { + say "dthumb version ${VERSION}"; + exit 0; + } + if ($self->{config}->{help}) { + say "Please refer to perldoc -F $0 (or man dthumb)"; + exit 0; + } +} + sub read_directories { my ($self) = @_; my $thumbdir = $self->{config}->{dir_thumbs}; -- cgit v1.2.3 From 48c650ef4122a31e7ef707b889a9806b90a58937 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 27 Feb 2011 18:09:36 +0100 Subject: Add (crude) option to disable lightbox --- bin/dthumb | 7 +++++++ lib/App/Dthumb.pm | 18 +++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/bin/dthumb b/bin/dthumb index 91286cf..fc76350 100755 --- a/bin/dthumb +++ b/bin/dthumb @@ -16,6 +16,7 @@ GetOptions( help|h size|d=i spacing|s=f + no-lightbox|L no-names|n quality|q=i version|v @@ -48,6 +49,12 @@ Note that recursion is not yet supported. =over +=item B<-L>, B<--no-lightbox> + +Disable Javascript lightbox. Note that in the current implementations, this +simple skips installation of the data files. The lightbox link in the HTML +will still be written, leading to 404s on the server. This will be fixed. + =item B<-n>, B<--no-names> Do not show image names below thumbnails diff --git a/lib/App/Dthumb.pm b/lib/App/Dthumb.pm index f26848f..ed1ed72 100755 --- a/lib/App/Dthumb.pm +++ b/lib/App/Dthumb.pm @@ -23,6 +23,7 @@ sub new { $conf->{size} //= 200; $conf->{spacing} //= 1.1; $conf->{quality} //= 75; + $conf->{lightbox} = !$conf->{'no-lightbox'}; $conf->{names} = !$conf->{'no-names'}; $ref->{config} = $conf; @@ -104,14 +105,17 @@ sub create_files { mkdir($thumbdir); } - if (not -d $datadir) { - mkdir($datadir); - } + if ($self->{config}->{lightbox}) { + + if (not -d $datadir) { + mkdir($datadir); + } - for my $file (qw(lightbox.js overlay.png loading.gif close.gif)) { - open(my $fh, '>', "${datadir}/${file}"); - print {$fh} $self->{data}->get($file); - close($fh); + for my $file (qw(lightbox.js overlay.png loading.gif close.gif)) { + open(my $fh, '>', "${datadir}/${file}"); + print {$fh} $self->{data}->get($file); + close($fh); + } } } -- cgit v1.2.3 From c8c5da39dbf4e1fa3a2d0ef57269cd797062ee8d Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 27 Feb 2011 18:38:44 +0100 Subject: Add progress bar --- Build.PL | 2 ++ README | 1 + bin/dthumb | 4 ++++ lib/App/Dthumb.pm | 19 ++++++++++++++++++- 4 files changed, 25 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/Build.PL b/Build.PL index 5ec738b..c93bbd7 100644 --- a/Build.PL +++ b/Build.PL @@ -21,7 +21,9 @@ my $build = Module::Build->new( 'Data::Section' => 0, 'Getopt::Long' => 0, 'Image::Imlib2' => 0, + 'IO::Handle' => 0, 'MIME::Base64' => 0, + 'Time::Progress' => 0, }, ); $build->create_build_script(); diff --git a/README b/README index 8678cef..f9fd483 100644 --- a/README +++ b/README @@ -4,6 +4,7 @@ Requires: * perl version 5.10 or newer * Data::Section * Image::Imlib2 + * Time::Progress Installation: diff --git a/bin/dthumb b/bin/dthumb index fc76350..f3eb2cd 100755 --- a/bin/dthumb +++ b/bin/dthumb @@ -45,6 +45,8 @@ images. Note that recursion is not yet supported. +During operation, B will show its progress on STDERR. + =head1 OPTIONS =over @@ -104,6 +106,8 @@ F<.dthumb>, which contains various data (so far icons and javascript code). =item * Image::Imlib2 +=item * Time::Progress + =back =head1 BUGS AND LIMITATIONS diff --git a/lib/App/Dthumb.pm b/lib/App/Dthumb.pm index ed1ed72..2a4ae27 100755 --- a/lib/App/Dthumb.pm +++ b/lib/App/Dthumb.pm @@ -10,11 +10,13 @@ use base 'Exporter'; use App::Dthumb::Data; use Cwd; use Image::Imlib2; +use IO::Handle; +use Time::Progress; our @EXPORT_OK = (); our $VERSION = '0.1'; -local $| = 1; +STDERR->autoflush(1); sub new { my ($obj, $conf) = @_; @@ -29,6 +31,7 @@ sub new { $ref->{config} = $conf; $ref->{data} = App::Dthumb::Data->new(); + $ref->{timer} = Time::Progress->new(); $ref->{html} = $ref->{data}->get('html_start'); @@ -94,6 +97,11 @@ sub read_directories { @{$self->{files}} = sort { lc($a) cmp lc($b) } @files; @{$self->{old_thumbnails}} = @old_thumbs; + + $self->{timer}->attr( + min => 1, + max => scalar @files, + ); } sub create_files { @@ -132,9 +140,16 @@ sub create_thumbnails { my ($self) = @_; for my $file (@{$self->{files}}) { + + print STDERR $self->{timer}->report( + "\r\e[KCreating Thumbnails: %p done, %L elapsed, %E remaining", + ++$self->{current_file_id}, + ); + $self->create_thumbnail_html($file); $self->create_thumbnail_image($file); } + print "\n"; } sub create_thumbnail_html { @@ -219,3 +234,5 @@ sub write_out_html { # } # return; #} + +1; -- cgit v1.2.3 From 3a00d48b65ed450bb4958dac8f9c8637c5bbf515 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 27 Feb 2011 18:40:03 +0100 Subject: App::Dthumb::Data generator: Use IO::Handle --- lib/App/Dthumb/Data.pm.PL | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/App/Dthumb/Data.pm.PL b/lib/App/Dthumb/Data.pm.PL index 1f04800..b07ed77 100644 --- a/lib/App/Dthumb/Data.pm.PL +++ b/lib/App/Dthumb/Data.pm.PL @@ -4,8 +4,8 @@ use warnings; use 5.010; use autodie; use MIME::Base64 qw(encode_base64); +use IO::Handle; -local $/ = undef; my ($out_file) = @ARGV; open(my $out_fh, '>', $out_file); @@ -19,6 +19,7 @@ for my $file (readdir($share_dh)) { } open(my $fh, '<', "share/${file}"); + $fh->input_record_separator(undef); my $content = <$fh>; close($fh); -- cgit v1.2.3 From 149e463ca5430c9327cbf4e516104bdc2dcea3ae Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 27 Feb 2011 18:43:45 +0100 Subject: "input_record_separator is not supported on a per-handle basis". Whoops. --- lib/App/Dthumb/Data.pm.PL | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/App/Dthumb/Data.pm.PL b/lib/App/Dthumb/Data.pm.PL index b07ed77..a9e8ed8 100644 --- a/lib/App/Dthumb/Data.pm.PL +++ b/lib/App/Dthumb/Data.pm.PL @@ -4,7 +4,6 @@ use warnings; use 5.010; use autodie; use MIME::Base64 qw(encode_base64); -use IO::Handle; my ($out_file) = @ARGV; @@ -19,8 +18,7 @@ for my $file (readdir($share_dh)) { } open(my $fh, '<', "share/${file}"); - $fh->input_record_separator(undef); - my $content = <$fh>; + my $content = do { local $/ = undef; <$fh> }; close($fh); if ($file =~ qr{ \. (png | gif) $ }ox) { -- cgit v1.2.3