summaryrefslogtreecommitdiffstats
path: root/generate_gallery.pl
diff options
context:
space:
mode:
Diffstat (limited to 'generate_gallery.pl')
-rwxr-xr-xgenerate_gallery.pl61
1 files changed, 61 insertions, 0 deletions
diff --git a/generate_gallery.pl b/generate_gallery.pl
new file mode 100755
index 0000000..64c9d6b
--- /dev/null
+++ b/generate_gallery.pl
@@ -0,0 +1,61 @@
+#!/usr/bin/perl
+use warnings;
+use strict;
+use Image::ExifTool qw(ImageInfo);
+use File::Basename;
+use Cwd qw(cwd abs_path);
+use File::MimeInfo qw(mimetype);
+use Image::Magick;
+
+if (@ARGV == 0) {
+ print "usage: ".basename($0)." <directory>...";
+ exit 0;
+}
+
+my $templatedir = abs_path(dirname($0))."/generate_gallery.d";
+
+my $startdir = cwd();
+
+for my $dir (@ARGV) {
+ chdir $startdir;
+ unless (-d $dir) {
+ print "Argument is not a directory: $dir. Ignoring.\n";
+ next;
+ }
+ my $abs_dir = abs_path $dir;
+ chdir $abs_dir;
+ mkdir "thumbs" unless -d "thumbs";
+ my $html;
+
+ for my $file (glob("*")) {
+ unless (mimetype($file) =~ /^image\/.*/) {
+ print "ignoring non-image: $dir/$file\n";
+ next;
+ }
+
+ unless ( -e "$abs_dir/thumbs/$file") {
+ print "processing $dir/$file ...\n";
+ my $img = new Image::Magick;
+ $img->Read("$abs_dir/$file");
+ $img->Thumbnail(geometry=>"200x200");
+ $img->Write("$abs_dir/thumbs/$file");
+ }
+ $html .= "<div class=\"thumbnail\">\n";
+ my $tags = ImageInfo($file, "Aperture", "ShutterSpeed", "FocalLength");
+ $html .= "<a rel=\"images\" class=\"thumbnail\" title=\"".$tags->{ShutterSpeed}.", ".$tags->{FocalLength}." @ F ".$tags->{Aperture}."\" href=\"$file\">\n";
+ $html .= "<img class=\"thumbnail\" alt=\"\" src=\"thumbs/$file\" />\n";
+ $html .= "</a>\n</div>\n";
+ }
+ open TEMPLATE, "<", "$templatedir/template.html";
+ open OUTPUT, ">", "$abs_dir/index.html";
+ while (<TEMPLATE>) {
+ if (/%%CONTENT%%/) {
+ print OUTPUT $html;
+ } else {
+ print OUTPUT $_;
+ }
+ }
+ close TEMPLATE;
+ close OUTPUT;
+ system "cp", "-r", "$templatedir/fancybox", ".";
+}