diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-02-28 18:13:19 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-02-28 18:13:19 +0100 |
commit | a0170383fc831c327c481844a2ce86f240b403da (patch) | |
tree | 58b21cbee01473edfc26e3ee2cc2df001b367e22 | |
parent | 011ed48f326216672f962e128f96cb83cef28460 (diff) | |
parent | 149e463ca5430c9327cbf4e516104bdc2dcea3ae (diff) |
Merge branch 'master' of /home/derf/var/git_root/dthumb
Conflicts:
lib/App/Dthumb.pm
-rw-r--r-- | Build.PL | 5 | ||||
-rw-r--r-- | Changelog | 9 | ||||
-rw-r--r-- | README | 8 | ||||
-rwxr-xr-x | bin/dthumb | 33 | ||||
-rwxr-xr-x | lib/App/Dthumb.pm | 60 | ||||
-rw-r--r-- | lib/App/Dthumb/Data.pm.PL | 3 | ||||
-rwxr-xr-x | t/00-compile-pm.t | 8 |
7 files changed, 96 insertions, 30 deletions
@@ -10,6 +10,7 @@ my $build = Module::Build->new( 'Test::Compile' => 0, 'Test::Pod' => 0, }, + dist_abstract => 'Generate Thumbnails + Index for a set of images', dist_name => 'dthumb', module_name => 'App::Dthumb', license => 'unrestricted', @@ -19,11 +20,13 @@ 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, + 'IO::Handle' => 0, + 'MIME::Base64' => 0, + 'Time::Progress' => 0, }, ); $build->create_build_script(); diff --git a/Changelog b/Changelog new file mode 100644 index 0000000..b22f6a8 --- /dev/null +++ b/Changelog @@ -0,0 +1,9 @@ +git HEAD + + * Add progressbar, introduces new dependency Time::Progress + +dthumb 0.1 - Sun Feb 27 2011 + + * Support for jpg/png with Image::Imlib2 + * Includes Javascript lightbox + * Some configuration via commandline arguments @@ -2,7 +2,9 @@ dthumb - Create static HTML thumbnail list for images Requires: * perl version 5.10 or newer - * The Image::Imlib2 perl module + * Data::Section + * Image::Imlib2 + * Time::Progress Installation: @@ -11,3 +13,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. @@ -13,11 +13,13 @@ my $opt = {}; GetOptions( $opt, qw{ + help|h size|d=i spacing|s=f + no-lightbox|L no-names|n quality|q=i - archive|x + version|v }, ) or die("Please see perldoc -F $0\n"); @@ -41,21 +43,19 @@ dthumb will create an F<index.xhtml> with a list (thumbnails) of all images found in the current directory; the thumbnails will link to the images. -The F<index.xhtml> file will always be created in the current directory, the -thumbnails will be saved in F<.thumbs> below it. - Note that recursion is not yet supported. +During operation, B<dthumb> will show its progress on STDERR. + =head1 OPTIONS =over -=item B<-x>, B<--archive> +=item B<-L>, B<--no-lightbox> -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. +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> @@ -88,25 +88,32 @@ Zero upon success, non-zero otherwise. None. +=head1 FILES + +B<dthumb> always works in the current working directory. It will create the +file F<index.xhtml>, in which the HTML code for the thumbnail list is saved. + +It also creates two directories: F<.thumbs> for the thumbnail images, and +F<.dthumb>, which contains various data (so far icons and javascript code). + =head1 DEPENDENCIES =over =item * autodie (Included in core as of perl 5.10.1) -=item * Archive::Tar (subject to change) +=item * Data::Section =item * Image::Imlib2 +=item * Time::Progress + =back =head1 BUGS AND LIMITATIONS 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 E<lt>derf@chaosdorf.deE<gt>. diff --git a/lib/App/Dthumb.pm b/lib/App/Dthumb.pm index ad927da..567c5f6 100755 --- a/lib/App/Dthumb.pm +++ b/lib/App/Dthumb.pm @@ -8,14 +8,15 @@ use 5.010; use base 'Exporter'; use App::Dthumb::Data; -use Archive::Tar; 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) = @_; @@ -24,11 +25,13 @@ 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; $ref->{data} = App::Dthumb::Data->new(); - $ref->{tar} = Archive::Tar->new(); + $ref->{timer} = Time::Progress->new(); $ref->{html} = $ref->{data}->get('html_start'); @@ -44,6 +47,7 @@ sub new { sub run { my ($self) = @_; + $self->check_cmd_flags(); $self->read_directories(); $self->create_files(); $self->delete_old_thumbnails(); @@ -51,6 +55,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}; @@ -79,6 +96,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 { @@ -90,15 +112,18 @@ 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(close.png loading.gif next.png pause.png play.png - previous.png shadowbox.css shadowbox.js)) { - open(my $fh, '>', "${datadir}/${file}"); - print {$fh} $self->{data}->get($file); - close($fh); + for my $file (qw(close.png loading.gif next.png pause.png play.png + previous.png shadowbox.css shadowbox.js)) { + open(my $fh, '>', "${datadir}/${file}"); + print {$fh} $self->{data}->get($file); + close($fh); + } } } @@ -115,15 +140,22 @@ 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 { 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( "<div style=\"%s; %s; %s; width: %dpx; height: %dpx\">\n", @@ -140,7 +172,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<br />\n" . "\t<a style=\"%s;\" href=\"%s\">%s</a>\n", @@ -202,3 +234,5 @@ sub write_out_html { # } # return; #} + +1; diff --git a/lib/App/Dthumb/Data.pm.PL b/lib/App/Dthumb/Data.pm.PL index 1f04800..a9e8ed8 100644 --- a/lib/App/Dthumb/Data.pm.PL +++ b/lib/App/Dthumb/Data.pm.PL @@ -5,7 +5,6 @@ use 5.010; use autodie; use MIME::Base64 qw(encode_base64); -local $/ = undef; my ($out_file) = @ARGV; open(my $out_fh, '>', $out_file); @@ -19,7 +18,7 @@ for my $file (readdir($share_dh)) { } open(my $fh, '<', "share/${file}"); - my $content = <$fh>; + my $content = do { local $/ = undef; <$fh> }; close($fh); if ($file =~ qr{ \. (png | gif) $ }ox) { diff --git a/t/00-compile-pm.t b/t/00-compile-pm.t new file mode 100755 index 0000000..2476ab2 --- /dev/null +++ b/t/00-compile-pm.t @@ -0,0 +1,8 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use 5.010; +use Test::More; +use Test::Compile; + +all_pm_files_ok(); |