#!/usr/bin/perl use strict; use warnings; use Image::Imlib2; my $directory = shift || '.'; my $thumbdir = "$directory/.thumbs"; my $indexfile = "$directory/index.xhtml"; my ($file, $image, $thumb); my ($dx, $dy); my @files; my $number = 0; sub print_progress { if (($number % 60) == 0) { if ($number) { printf(" %4d/%d\n", $number, scalar(@files)); } printf('[%3d%%] ', $number * 100 / @files); } elsif (($number % 10) == 0) { print ' '; } } $| = 1; open(my $index, '>', $indexfile); print $index <
ficken if (! -d $thumbdir) { mkdir($thumbdir) or die("cannot create $thumbdir: $!"); } opendir(my $dirhandle, $directory) or die("Cannot open $directory: $!"); foreach $file (readdir($dirhandle)) { push(@files, $file) if ($file =~ /\.(png|jpe?g)$/i); } closedir($dirhandle); print "Generating thumbnails [ - cached | + generated ]\n"; foreach $file (@files) { print $index < ficken print_progress; $number++; if (-e "$thumbdir/$file") { print '-'; next; } $image = Image::Imlib2->load($file); ($dx, $dy) = ($image->width, $image->height); if ($dx > $dy) { $thumb = $image->create_scaled_image(150, 0); } else { $thumb = $image->create_scaled_image(0, 150); } $thumb->set_quality(60); $thumb->save("$thumbdir/$file"); chmod(0644, "$thumbdir/$file"); print '+'; } print "\n"; print $index < ficken close($index); chmod(0644, $indexfile);