From 3a7baab7344d933e9534716ddd9ff88645dcecfa Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Fri, 24 Mar 2017 17:28:21 +0100 Subject: begin work on recursive mode. isn't recursive yet, but does list directories. --- bin/dthumb | 13 +++++++------ lib/App/Dthumb.pm | 34 ++++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 14 deletions(-) diff --git a/bin/dthumb b/bin/dthumb index 0ba3e89..ab56865 100755 --- a/bin/dthumb +++ b/bin/dthumb @@ -27,6 +27,7 @@ GetOptions( no-names|n quality|q=i recreate|r + recursive|R size|d=i spacing|s=f title|t=s @@ -46,16 +47,16 @@ if ( $opt->{help} ) { die("Please see 'perldoc -F $0' or 'man dthumb'\n"); } -$dthumb->read_directories(); -$dthumb->create_files(); -$dthumb->delete_old_thumbnails(); +$dthumb->read_directories; +$dthumb->create_files; +$dthumb->delete_old_thumbnails; $timer->attr( min => 1, - max => scalar $dthumb->get_files(), + max => scalar $dthumb->get_files, ); -for my $file ( $dthumb->get_files() ) { +for my $file ( $dthumb->get_files ) { print STDERR $timer->report( "\r\e[KCreating Thumbnails: %p done, %L elapsed, %E remaining", $id++, ); @@ -65,7 +66,7 @@ for my $file ( $dthumb->get_files() ) { } print "\n"; -$dthumb->write_out_html(); +$dthumb->write_out_html; __END__ diff --git a/lib/App/Dthumb.pm b/lib/App/Dthumb.pm index b6024a6..6e4eeaf 100755 --- a/lib/App/Dthumb.pm +++ b/lib/App/Dthumb.pm @@ -53,11 +53,17 @@ sub read_directories { my ( @files, @old_thumbs ); for my $file ( read_dir($imgdir) ) { + if ( $file =~ m{ ^ [.] }x ) { + next; + } if ( -f "${imgdir}/${file}" and $file =~ qr{ [.] (png | jp e? g) $ }iox ) { push( @files, $file ); } + elsif ( $self->{config}{recursive} and -d "${imgdir}/${file}" ) { + push( @files, $file ); + } } if ( -d $thumbdir ) { @@ -120,15 +126,24 @@ sub create_thumbnail_html { $self->{html} .= "
\n"; - $self->{html} .= sprintf( + if ( -d $file ) { + $self->{html} + .= sprintf( "\t\n" - . "\t\t\"%s\"\n", - ($file) x 2, - $self->{config}->{dir_thumbs}, - ($file) x 2, - ); + . "\t\t\"%s\"\n", + ($file) x 2, $file, ); + } + else { + $self->{html} .= sprintf( +"\t\n" + . "\t\t\"%s\"\n", + ($file) x 2, + $self->{config}->{dir_thumbs}, + ($file) x 2, + ); + } - if ( $self->{config}->{names} ) { + if ( $self->{config}->{names} or -d $file ) { $self->{html} .= sprintf( "\t
\n" . "\t%s\n", 'text-decoration: none', @@ -153,9 +168,12 @@ sub create_thumbnail_image { { return; } + if ( -d $file ) { + return; + } my $image = Image::Imlib2->load($file); - my ( $dx, $dy ) = ( $image->width(), $image->height() ); + my ( $dx, $dy ) = ( $image->width, $image->height ); my $thumb = $image; if ( $dx > $thumb_dim or $dy > $thumb_dim ) { -- cgit v1.2.3