From 56aaf758eecf3fd86c21fbf14e4797165ba8f22f Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 16 Apr 2009 13:31:33 +0200 Subject: initial commit --- include/gen-xhtml-thumbnails | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 include/gen-xhtml-thumbnails diff --git a/include/gen-xhtml-thumbnails b/include/gen-xhtml-thumbnails new file mode 100755 index 0000000..3c64ea9 --- /dev/null +++ b/include/gen-xhtml-thumbnails @@ -0,0 +1,62 @@ +#!/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, $tx, $ty); +$| = 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: $!"); +print "Generating thumbnails [ - cached | + generated ]\n"; +foreach $file (readdir($dirhandle)) { + next unless ($file =~ /\.(png|jpe?g)$/i); + +print $index < +ficken + + 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); -- cgit v1.2.3