]> mj.ucw.cz Git - gallery.git/commitdiff
Gallery2: Subcommands
authorMartin Mares <mj@ucw.cz>
Wed, 26 Dec 2012 20:20:43 +0000 (21:20 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 8 Feb 2015 20:14:09 +0000 (21:14 +0100)
15 files changed:
gal2/bin/gal-cache [new file with mode: 0755]
gal2/bin/gal-dump-config [new file with mode: 0755]
gal2/bin/gal-dump-meta [new file with mode: 0755]
gal2/bin/gal-from-gqview [new file with mode: 0755]
gal2/bin/gal-gen [new file with mode: 0755]
gal2/bin/gal-mj-digikam [new file with mode: 0755]
gal2/bin/gal-mj-init [new file with mode: 0755]
gal2/bin/gal-scan [new file with mode: 0755]
gal2/gal [new file with mode: 0755]
gal2/gal-cache [deleted file]
gal2/gal-dump-config [deleted file]
gal2/gal-dump-meta [deleted file]
gal2/gal-from-gqview [deleted file]
gal2/gal-gen [deleted file]
gal2/gal-scan [deleted file]

diff --git a/gal2/bin/gal-cache b/gal2/bin/gal-cache
new file mode 100755 (executable)
index 0000000..2039d1b
--- /dev/null
@@ -0,0 +1,93 @@
+#!/usr/bin/perl
+# UCW Gallery: Prepare cache
+# (c) 2004--2012 Martin Mares <mj@ucw.cz>
+
+use strict;
+use warnings;
+
+use UCW::Gallery;
+use Image::Magick;
+use IO::Handle;
+use File::Spec;
+use File::Path;
+
+STDOUT->autoflush(1);
+
+my $gal = UCW::Gallery->load_config;
+
+print "Reading gallery.list\n";
+my $orig_list = $gal->read_list('gallery.list') or die "Cannot read gallery.list: $!\n";
+
+my $photo_dir = $gal->get('PhotoDir');
+my $photo_meta = File::Spec->catfile($photo_dir, 'gallery.meta');
+print "Reading meta-data from $photo_meta\n";
+-f $photo_meta or die "Cannot load $photo_meta\n";
+my $meta = $gal->read_meta($photo_meta);
+
+my $cache_dir = $gal->get('CacheDir');
+if (-d $cache_dir) {
+       print "Deleting old cache directory: $cache_dir\n";
+       File::Path::remove_tree($cache_dir);
+}
+print "Creating cache directory: $cache_dir\n";
+File::Path::mkpath($cache_dir) or die "Unable to create $cache_dir: $!\n";
+
+# Construct sequence and store photo titles
+$meta->{sequence} = [];
+for my $f (@$orig_list) {
+       push @{$meta->{sequence}}, $f->{id};
+       my $m = $meta->{photo}->{$f->{id}} or die;
+       $m->{title} = $f->{title};
+}
+
+for my $thumb_fmt (keys %{$gal->get('ThumbFormats')}) {
+       my ($tw, $th) = ($thumb_fmt =~ m{^(\d+)x(\d+)$}) or die "Cannot parse thumbnail format $thumb_fmt\n";
+       print "Generating $thumb_fmt thumbnails\n";
+       my $thumb_meta = {};
+       $meta->{thumb}->{$thumb_fmt} = $thumb_meta;
+       my $thumb_dir = File::Spec->catfile($cache_dir, $thumb_fmt);
+       -d $thumb_dir or File::Path::mkpath($thumb_dir) or die "Unable to create $thumb_dir: $!\n";
+
+       for my $id (@{$meta->{sequence}}) {
+               my $m = $meta->{photo}->{$id} or die;
+               print "\t$id: ";
+
+               my $p = new Image::Magick;
+               my $photo = File::Spec->catfile($photo_dir, "$id.jpg");
+               my $e;
+               $e = $p->Read($photo) and die "Error reading $photo: $e";
+
+               my $w = $m->{w};
+               my $h = $m->{h};
+               if ($w > $tw) {
+                       my $s = $tw / $w;
+                       $w = $w * $s;
+                       $h = $h * $s;
+               }
+               if ($h > $th) {
+                       my $s = $th / $h;
+                       $w = $w * $s;
+                       $h = $h * $s;
+               }
+               $w = int($w);
+               $h = int($h);
+               print "${w}x${h} ";
+               $p->Resize(width=>$w, height=>$h);
+
+               my $out = File::Spec->catfile($thumb_dir, "$id.jpg");
+               my $tmp = "$photo.new";
+               $e = $p->Write($tmp) and die "Unable to write $tmp: $e";
+               rename $tmp, $out or die "Unable to rename $tmp to $out: $!\n";
+
+               $thumb_meta->{$id} = {
+                       'w' => $w,
+                       'h' => $h,
+               };
+
+               print "... OK\n";
+       }
+}
+
+my $cache_meta = File::Spec->catfile($cache_dir, 'cache.meta');
+print "Writing meta-data to $cache_meta\n";
+$gal->write_meta($cache_meta, $meta);
diff --git a/gal2/bin/gal-dump-config b/gal2/bin/gal-dump-config
new file mode 100755 (executable)
index 0000000..600a9d5
--- /dev/null
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+# UCW Gallery: Show configuration variables
+# (c) 2004--2012 Martin Mares <mj@ucw.cz>
+
+use strict;
+use warnings;
+
+use UCW::Gallery;
+use Data::Dumper;
+
+my $gal = UCW::Gallery->load_config();
+
+for my $k (sort $gal->get_config_keys) {
+       my $d = Data::Dumper->new([ $gal->get($k) ]);
+       $d->Terse(1);
+       print "$k=", $d->Dump;
+}
diff --git a/gal2/bin/gal-dump-meta b/gal2/bin/gal-dump-meta
new file mode 100755 (executable)
index 0000000..1734183
--- /dev/null
@@ -0,0 +1,15 @@
+#!/usr/bin/perl
+# UCW Gallery: Dump meta-data
+# (c) 2004--2012 Martin Mares <mj@ucw.cz>
+
+use strict;
+use warnings;
+
+use UCW::Gallery;
+use Data::Dumper;
+
+@ARGV == 1 or die "Usage: $0 <meta-file>\n";
+
+my $gal = UCW::Gallery->load_config;
+my $meta = $gal->read_meta($ARGV[0]);
+print Dumper($meta);
diff --git a/gal2/bin/gal-from-gqview b/gal2/bin/gal-from-gqview
new file mode 100755 (executable)
index 0000000..138af5a
--- /dev/null
@@ -0,0 +1,17 @@
+#!/usr/bin/perl
+# UCW Gallery: Extract image list from GQview collection
+# (c) 2004--2012 Martin Mares <mj@ucw.cz>
+
+use strict;
+use warnings;
+
+while (<>) {
+       chomp;
+       /^#/ && next;
+       /^$/ && next;
+       if (/^"(.*)"$/) {
+               print "$1\n";
+       } else {
+               die "Error parsing collection: $_";
+       }
+}
diff --git a/gal2/bin/gal-gen b/gal2/bin/gal-gen
new file mode 100755 (executable)
index 0000000..6c767d8
--- /dev/null
@@ -0,0 +1,123 @@
+#!/usr/bin/perl
+# UCW Gallery: Generate published photos
+# (c) 2004--2012 Martin Mares <mj@ucw.cz>
+
+use strict;
+use warnings;
+
+use UCW::Gallery;
+use Image::Magick;
+use IO::Handle;
+use File::Spec;
+use File::Path;
+
+STDOUT->autoflush(1);
+
+my $gal = UCW::Gallery->load_config;
+
+my $orig_list = $gal->read_list('gallery.list') or die "Cannot read gallery.list: $!\n";
+
+my $photo_dir = $gal->get('PhotoDir');
+if (-d $photo_dir) {
+       print "Using existing output directory: $photo_dir\n";
+} else {
+       print "Creating output directory: $photo_dir\n";
+       File::Path::mkpath($photo_dir) or die "Unable to create $photo_dir: $!\n";
+}
+
+my $photo_meta = $photo_dir . "/gallery.meta";
+my $old_meta = {};
+if (-f $photo_meta) {
+       print "Reading old meta-data\n";
+       $old_meta = $gal->read_meta($photo_meta);
+       # use Data::Dumper; print "Read old meta: ", Dumper($old_meta), "\n";
+}
+my $meta = { 'photo' => {} };
+
+for my $f (@$orig_list) {
+       my $id = $f->{id};
+       my $rotate = $f->{orientation};
+       my $xfrm = $f->{xfrm};
+       print "$id: ";
+
+       my $p = new Image::Magick;
+       my $orig = File::Spec->rel2abs($f->{file}, $gal->get('OrigDir'));
+       my ($orig_w, $orig_h, $orig_size, $orig_format) = $p->PingImage($orig) or die "Error reading $orig\n";
+       print "${orig_w}x${orig_h} ";
+
+       my ($w0, $h0) = ($rotate eq "l" || $rotate eq "r") ? ($orig_h, $orig_w) : ($orig_w, $orig_h);
+       my ($w, $h) = ($w0, $h0);
+       if ($w > $gal->get('PhotoMaxWidth')) {
+               my $s = $gal->get('PhotoMaxWidth') / $w;
+               $w = $w * $s;
+               $h = $h * $s;
+       }
+       if ($h > $gal->get('PhotoMaxHeight')) {
+               my $s = $gal->get('PhotoMaxHeight') / $h;
+               $w = $w * $s;
+               $h = $h * $s;
+       }
+       $w = int($w);
+       $h = int($h);
+       
+       my $m = {
+               'o' => $rotate,
+               'xf' => $xfrm,
+               'w' => $w,
+               'h' => $h,
+       };
+       $meta->{photo}->{$id} = $m;
+
+       my $om = $old_meta->{photo}->{$id};
+       if ($om &&
+           $om->{o} eq $m->{o} &&
+           $om->{xf} eq $m->{xf} &&
+           $om->{w} eq $m->{w} &&
+           $om->{h} eq $m->{h}) {
+               # FIXME: Remove old images?
+               print "... uptodate\n";
+               next;
+       }
+
+       my $e;
+       $e = $p->Read($orig) and die "Error reading $orig: $e";
+       $p->Strip;
+       $p->SetAttribute(quality=>90);
+
+       if ($xfrm =~ /s/) {
+               print "-> sharpen ";
+               $p->Sharpen(1);
+       }
+       if ($xfrm =~ /h/) {
+               print "-> equalize ";
+               $p->Equalize();
+       }
+       if ($xfrm =~ /n/) {
+               print "-> normalize ";
+               $p->Normalize();
+       }
+
+       my $rot = 0;
+       if ($rotate eq "l") { $rot = 270; }
+       elsif ($rotate eq "r") { $rot = 90; }
+       elsif ($rotate eq "u") { $rot = 180; }
+       if ($rot) {
+               print "-> rotate $rot ";
+               $p->Rotate(degrees=>$rot);
+       }
+
+       if ($w != $w0 || $h != $h0) {
+               print "-> ${w}x${h} ";
+               $p->Resize(width=>$w, height=>$h);
+       }
+
+       my $photo = File::Spec->catfile($photo_dir, $id . ".jpg");
+       my $tmp = "$photo.new";
+       $e = $p->Write($tmp) and die "Unable to write $tmp: $e";
+       rename $tmp, $photo or die "Cannot rename $tmp to $photo: $!\n";
+
+       print "... OK\n";
+}
+
+print "Writing meta-data\n";
+$gal->write_meta($photo_meta, $meta);
diff --git a/gal2/bin/gal-mj-digikam b/gal2/bin/gal-mj-digikam
new file mode 100755 (executable)
index 0000000..134bfc0
--- /dev/null
@@ -0,0 +1,44 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Cwd;
+use DBI;
+
+my $photos_root = $ENV{HOME} . '/photos';
+
+my $album = $ARGV[0];
+if (!defined $album) {
+       my $cwd = getcwd;
+       $cwd =~ m{/photos/(.*)} or die "Cannot identify album from current directory, need to specify maunally.\n";
+       $album = $1;
+}
+
+my $dbfile = "$photos_root/digikam4.db";
+my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "") or die "Cannot access $dbfile\n";
+
+my %alba = ();
+for my $r (@{$dbh->selectall_arrayref(
+       'SELECT a.id AS id, r.label AS label, a.relativePath AS rpath FROM Albums a JOIN AlbumRoots r ON (r.id = a.albumRoot)',
+       { Slice => {} })}) {
+       my $name = $r->{label} . $r->{rpath};
+       # print "$name\n";
+       $alba{$name} = $r->{id};
+}
+
+my $album_id = $alba{$album} // die "Unknown album $album\n";
+print "## Album $album: id=$album_id\n";
+
+my ($tag_id) = $dbh->selectrow_array('SELECT id FROM Tags WHERE pid=0 AND name="web"');
+$tag_id // die "Cannot find web tag\n";
+print "## Tag ID: $tag_id\n";
+
+open OUT, '|-', $ENV{GALLERY_ROOT} . '/bin/gal-scan' or die "Cannot feed gal scan\n";
+for my $r (@{$dbh->selectall_arrayref(
+       'SELECT i.name AS name FROM Images i JOIN ImageTags t ON (i.id = t.imageid) WHERE i.album=? AND t.tagid=? ORDER BY i.name',
+       { Slice => {} },
+       $album_id, $tag_id)}) {
+       print OUT "$photos_root/$album/" . $r->{name}, "\n";
+}
+close OUT;
diff --git a/gal2/bin/gal-mj-init b/gal2/bin/gal-mj-init
new file mode 100755 (executable)
index 0000000..1105254
--- /dev/null
@@ -0,0 +1,20 @@
+#!/bin/sh
+set -e
+
+if [ -f gallery.cf ] ; then
+       echo >&2 'gallery.cf already present, giving up!'
+       exit 1
+fi
+
+cat >gallery.cf <<'AMEN'
+use strict;
+use warnings;
+use utf8;
+
+my $gal = require '../../default.cf';
+$gal->set(
+       Title => 'Unnamed',
+);
+
+return $gal;
+AMEN
diff --git a/gal2/bin/gal-scan b/gal2/bin/gal-scan
new file mode 100755 (executable)
index 0000000..4610980
--- /dev/null
@@ -0,0 +1,115 @@
+#!/usr/bin/perl
+# UCW Gallery: Scan images and generate image list
+# (c) 2004--2012 Martin Mares <mj@ucw.cz>
+
+use strict;
+use warnings;
+
+use UCW::Gallery;
+use File::Spec;
+use Image::EXIF;
+use Digest::SHA;
+
+if (@ARGV && $ARGV[0] eq '--help') {
+       die <<AMEN ;
+Usage: cat list | gal scan
+   or: gal scan <files and directories>
+AMEN
+}
+
+my @files = ();
+if (@ARGV) {
+       for my $in (@ARGV) {
+               if (-f $in) {
+                       push @files, $in;
+               } elsif (-d $in) {
+                       opendir D, $in or die "Cannot scan directory $in: $!\n";
+                       my @p = ();
+                       while (my $e = readdir D) {
+                               my $f = File::Spec->canonpath(File::Spec->catfile($in, $e));
+                               if ($f =~ m{\.(jpe?g|png)$}i) {
+                                       push @p, $f;
+                               }
+                       }
+                       closedir D;
+                       push @files, sort @p;
+               } else {
+                       die "$in is neither file nor directory\n";
+               }
+       }
+} else {
+       while (<STDIN>) {
+               chomp;
+               push @files, $_;
+       }
+}
+
+STDOUT->autoflush(1);
+
+my $gal = UCW::Gallery->load_config;
+my $orig_prefix = $gal->get('OrigDir');
+$orig_prefix =~ m{/$} or $orig_prefix .= '/';
+
+print "Scanning photos\n";
+my @images = ();
+foreach my $f (@files) {
+       my $rel_name = $f;
+       if (substr($rel_name, 0, length $orig_prefix) eq $orig_prefix) {
+               $rel_name = substr($rel_name, length $orig_prefix);
+       }
+       print "\t$rel_name: ";
+
+       my $sha = Digest::SHA->new(1);
+       $sha->addfile($f) or die "Cannot hash $f\n";
+       my $id = substr($sha->hexdigest, 0, 16);
+       print "id=$id ";
+
+       my $e = new Image::EXIF($f);
+       my $i = $e->get_all_info();
+       if ($e->error) { print "EXIF error: ", $e->error, "\n"; }
+       else {
+               # print STDERR Dumper($i), "\n";
+               my $o = $i->{'image'}->{'Image Orientation'} || "Top, Left-Hand";
+               if ($o eq "Top, Left-Hand") { $o = "."; }
+               elsif ($o eq "Right-Hand, Top") { $o = "r"; }
+               elsif ($o eq "Left-Hand, Bottom") { $o = "l"; }
+               elsif ($o eq "Bottom, Right-Hand") { $o = "d"; }
+               else {
+                       print "Unrecognized orientation: $o\n";
+                       $o = ".";
+               }
+               push @images, {
+                       file => $rel_name,
+                       id => $id,
+                       orientation => $o,
+                       xfrm => $gal->get('ScanDefaultTransform'),
+                       title => '',
+               };
+               print "ori=$o\n";
+       }
+}
+
+my $old = $gal->read_list('gallery.list');
+if ($old) {
+       print "Updating gallery.list\n";
+       my %old_by_id = map { $_->{id} => $_ } @$old;
+       for my $i (@images) {
+               my $id = $i->{id};
+               my $o = $old_by_id{$id};
+               if ($o) {
+                       print "\t$id: updated\n";
+                       $i->{orientation} = $o->{orientation};
+                       $i->{xfrm} = $o->{xfrm};
+                       $i->{title} = $o->{title};
+               } else {
+                       print "\t$id: new\n";
+               }
+               delete $old_by_id{$id};
+       }
+       for my $id (keys %old_by_id) {
+               print "\t$id: removed\n";
+       }
+}
+
+$gal->write_list('gallery.list', \@images);
+print "Written gallery.list (", (scalar @images), " items)\n";
diff --git a/gal2/gal b/gal2/gal
new file mode 100755 (executable)
index 0000000..d8dd694
--- /dev/null
+++ b/gal2/gal
@@ -0,0 +1,53 @@
+#!/usr/bin/perl
+# UCW Gallery -- Master Program
+# (c) 2012 Martin Mares <mj@ucw.cz>
+
+use strict;
+use warnings;
+use Getopt::Long;
+
+use FindBin;
+my $gallery_root = $FindBin::Bin;
+
+sub show_help() {
+       print <<AMEN ;
+Usage: gal <general-options> <command> <command-options> <args>
+
+General options:
+(none yet)
+
+Common commands:
+scan           Scan directory and obtain originals
+gen            Generate web photos from originals
+cache          Rebuild thumbnails and other cached info
+
+Other commands:
+dump-config    Show configuration settings
+dump-meta      Show contents of metadata files
+from-gqview    Parse gqview/geeqie collections
+AMEN
+       exit 0;
+}
+
+Getopt::Long::Configure('require_order');
+GetOptions(
+       "help" => \&show_help,
+       "version" => sub {
+                       print "UCW Gallery 2.0 (c) 2004-2012 Martin Mares <mj\@ucw.cz>\n";
+               },
+) or die "Try `gal help' for more information.\n";
+Getopt::Long::Configure('default');
+
+@ARGV or die "Missing subcommand.\n";
+my $sub = shift @ARGV;
+$sub =~ /^[0-9a-zA-Z-]+$/ or die "Invalid subcommand $sub\n";
+
+if ($sub eq 'help') { show_help(); }
+
+my $sub_path = "$gallery_root/bin/gal-$sub";
+-x $sub_path or die "Unknown subcommand $sub\n";
+
+$ENV{"GALLERY_ROOT"} = $gallery_root;
+$ENV{"PERL5LIB"} = join(":", $gallery_root, $ENV{"PERL5LIB"} // ());
+exec $sub_path, @ARGV;
+die "Cannot execute $sub_path: $!\n";
diff --git a/gal2/gal-cache b/gal2/gal-cache
deleted file mode 100755 (executable)
index 7d581a6..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-#!/usr/bin/perl
-# UCW Gallery: Prepare cache
-# (c) 2004--2012 Martin Mares <mj@ucw.cz>
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib $FindBin::Bin;
-use UCW::Gallery;
-
-use Image::Magick;
-use IO::Handle;
-use File::Spec;
-use File::Path;
-
-STDOUT->autoflush(1);
-
-my $gal = UCW::Gallery->load_config;
-
-print "Reading gallery.list\n";
-my $orig_list = $gal->read_list('gallery.list') or die "Cannot read gallery.list: $!\n";
-
-my $photo_dir = $gal->get('PhotoDir');
-my $photo_meta = File::Spec->catfile($photo_dir, 'gallery.meta');
-print "Reading meta-data from $photo_meta\n";
--f $photo_meta or die "Cannot load $photo_meta\n";
-my $meta = $gal->read_meta($photo_meta);
-
-my $cache_dir = $gal->get('CacheDir');
-if (-d $cache_dir) {
-       print "Deleting old cache directory: $cache_dir\n";
-       File::Path::remove_tree($cache_dir);
-}
-print "Creating cache directory: $cache_dir\n";
-File::Path::mkpath($cache_dir) or die "Unable to create $cache_dir: $!\n";
-
-# Construct sequence and store photo titles
-$meta->{sequence} = [];
-for my $f (@$orig_list) {
-       push @{$meta->{sequence}}, $f->{id};
-       my $m = $meta->{photo}->{$f->{id}} or die;
-       $m->{title} = $f->{title};
-}
-
-for my $thumb_fmt (keys %{$gal->get('ThumbFormats')}) {
-       my ($tw, $th) = ($thumb_fmt =~ m{^(\d+)x(\d+)$}) or die "Cannot parse thumbnail format $thumb_fmt\n";
-       print "Generating $thumb_fmt thumbnails\n";
-       my $thumb_meta = {};
-       $meta->{thumb}->{$thumb_fmt} = $thumb_meta;
-       my $thumb_dir = File::Spec->catfile($cache_dir, $thumb_fmt);
-       -d $thumb_dir or File::Path::mkpath($thumb_dir) or die "Unable to create $thumb_dir: $!\n";
-
-       for my $id (@{$meta->{sequence}}) {
-               my $m = $meta->{photo}->{$id} or die;
-               print "\t$id: ";
-
-               my $p = new Image::Magick;
-               my $photo = File::Spec->catfile($photo_dir, "$id.jpg");
-               my $e;
-               $e = $p->Read($photo) and die "Error reading $photo: $e";
-
-               my $w = $m->{w};
-               my $h = $m->{h};
-               if ($w > $tw) {
-                       my $s = $tw / $w;
-                       $w = $w * $s;
-                       $h = $h * $s;
-               }
-               if ($h > $th) {
-                       my $s = $th / $h;
-                       $w = $w * $s;
-                       $h = $h * $s;
-               }
-               $w = int($w);
-               $h = int($h);
-               print "${w}x${h} ";
-               $p->Resize(width=>$w, height=>$h);
-
-               my $out = File::Spec->catfile($thumb_dir, "$id.jpg");
-               my $tmp = "$photo.new";
-               $e = $p->Write($tmp) and die "Unable to write $tmp: $e";
-               rename $tmp, $out or die "Unable to rename $tmp to $out: $!\n";
-
-               $thumb_meta->{$id} = {
-                       'w' => $w,
-                       'h' => $h,
-               };
-
-               print "... OK\n";
-       }
-}
-
-my $cache_meta = File::Spec->catfile($cache_dir, 'cache.meta');
-print "Writing meta-data to $cache_meta\n";
-$gal->write_meta($cache_meta, $meta);
diff --git a/gal2/gal-dump-config b/gal2/gal-dump-config
deleted file mode 100755 (executable)
index 1432c2e..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/usr/bin/perl
-# UCW Gallery: Show configuration variables
-# (c) 2004--2012 Martin Mares <mj@ucw.cz>
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib $FindBin::Bin;
-use UCW::Gallery;
-use Data::Dumper;
-
-my $gal = UCW::Gallery->load_config();
-
-for my $k (sort $gal->get_config_keys) {
-       my $d = Data::Dumper->new([ $gal->get($k) ]);
-       $d->Terse(1);
-       print "$k=", $d->Dump;
-}
diff --git a/gal2/gal-dump-meta b/gal2/gal-dump-meta
deleted file mode 100755 (executable)
index 28dbd93..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/usr/bin/perl
-# UCW Gallery: Dump meta-data
-# (c) 2004--2012 Martin Mares <mj@ucw.cz>
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib $FindBin::Bin;
-use UCW::Gallery;
-use Data::Dumper;
-
-@ARGV == 1 or die "Usage: $0 <meta-file>\n";
-
-my $gal = UCW::Gallery->load_config;
-my $meta = $gal->read_meta($ARGV[0]);
-print Dumper($meta);
diff --git a/gal2/gal-from-gqview b/gal2/gal-from-gqview
deleted file mode 100755 (executable)
index 138af5a..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#!/usr/bin/perl
-# UCW Gallery: Extract image list from GQview collection
-# (c) 2004--2012 Martin Mares <mj@ucw.cz>
-
-use strict;
-use warnings;
-
-while (<>) {
-       chomp;
-       /^#/ && next;
-       /^$/ && next;
-       if (/^"(.*)"$/) {
-               print "$1\n";
-       } else {
-               die "Error parsing collection: $_";
-       }
-}
diff --git a/gal2/gal-gen b/gal2/gal-gen
deleted file mode 100755 (executable)
index bc9c8b6..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-#!/usr/bin/perl
-# UCW Gallery: Generate published photos
-# (c) 2004--2012 Martin Mares <mj@ucw.cz>
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib $FindBin::Bin;
-use UCW::Gallery;
-
-use Image::Magick;
-use IO::Handle;
-use File::Spec;
-use File::Path;
-
-STDOUT->autoflush(1);
-
-my $gal = UCW::Gallery->load_config;
-
-my $orig_list = $gal->read_list('gallery.list') or die "Cannot read gallery.list: $!\n";
-
-my $photo_dir = $gal->get('PhotoDir');
-if (-d $photo_dir) {
-       print "Using existing output directory: $photo_dir\n";
-} else {
-       print "Creating output directory: $photo_dir\n";
-       File::Path::mkpath($photo_dir) or die "Unable to create $photo_dir: $!\n";
-}
-
-my $photo_meta = $photo_dir . "/gallery.meta";
-my $old_meta = {};
-if (-f $photo_meta) {
-       print "Reading old meta-data\n";
-       $old_meta = $gal->read_meta($photo_meta);
-       # use Data::Dumper; print "Read old meta: ", Dumper($old_meta), "\n";
-}
-my $meta = { 'photo' => {} };
-
-for my $f (@$orig_list) {
-       my $id = $f->{id};
-       my $rotate = $f->{orientation};
-       my $xfrm = $f->{xfrm};
-       print "$id: ";
-
-       my $p = new Image::Magick;
-       my $orig = File::Spec->rel2abs($f->{file}, $gal->get('OrigDir'));
-       my ($orig_w, $orig_h, $orig_size, $orig_format) = $p->PingImage($orig) or die "Error reading $orig\n";
-       print "${orig_w}x${orig_h} ";
-
-       my ($w0, $h0) = ($rotate eq "l" || $rotate eq "r") ? ($orig_h, $orig_w) : ($orig_w, $orig_h);
-       my ($w, $h) = ($w0, $h0);
-       if ($w > $gal->get('PhotoMaxWidth')) {
-               my $s = $gal->get('PhotoMaxWidth') / $w;
-               $w = $w * $s;
-               $h = $h * $s;
-       }
-       if ($h > $gal->get('PhotoMaxHeight')) {
-               my $s = $gal->get('PhotoMaxHeight') / $h;
-               $w = $w * $s;
-               $h = $h * $s;
-       }
-       $w = int($w);
-       $h = int($h);
-       
-       my $m = {
-               'o' => $rotate,
-               'xf' => $xfrm,
-               'w' => $w,
-               'h' => $h,
-       };
-       $meta->{photo}->{$id} = $m;
-
-       my $om = $old_meta->{photo}->{$id};
-       if ($om &&
-           $om->{o} eq $m->{o} &&
-           $om->{xf} eq $m->{xf} &&
-           $om->{w} eq $m->{w} &&
-           $om->{h} eq $m->{h}) {
-               # FIXME: Remove old images?
-               print "... uptodate\n";
-               next;
-       }
-
-       my $e;
-       $e = $p->Read($orig) and die "Error reading $orig: $e";
-       $p->Strip;
-       $p->SetAttribute(quality=>90);
-
-       if ($xfrm =~ /s/) {
-               print "-> sharpen ";
-               $p->Sharpen(1);
-       }
-       if ($xfrm =~ /h/) {
-               print "-> equalize ";
-               $p->Equalize();
-       }
-       if ($xfrm =~ /n/) {
-               print "-> normalize ";
-               $p->Normalize();
-       }
-
-       my $rot = 0;
-       if ($rotate eq "l") { $rot = 270; }
-       elsif ($rotate eq "r") { $rot = 90; }
-       elsif ($rotate eq "u") { $rot = 180; }
-       if ($rot) {
-               print "-> rotate $rot ";
-               $p->Rotate(degrees=>$rot);
-       }
-
-       if ($w != $w0 || $h != $h0) {
-               print "-> ${w}x${h} ";
-               $p->Resize(width=>$w, height=>$h);
-       }
-
-       my $photo = File::Spec->catfile($photo_dir, $id . ".jpg");
-       my $tmp = "$photo.new";
-       $e = $p->Write($tmp) and die "Unable to write $tmp: $e";
-       rename $tmp, $photo or die "Cannot rename $tmp to $photo: $!\n";
-
-       print "... OK\n";
-}
-
-print "Writing meta-data\n";
-$gal->write_meta($photo_meta, $meta);
diff --git a/gal2/gal-scan b/gal2/gal-scan
deleted file mode 100755 (executable)
index 02eb33d..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-#!/usr/bin/perl
-# UCW Gallery: Scan images and generate image list
-# (c) 2004--2012 Martin Mares <mj@ucw.cz>
-
-use strict;
-use warnings;
-
-use FindBin;
-use lib $FindBin::Bin;
-use UCW::Gallery;
-
-use File::Spec;
-use Image::EXIF;
-use Digest::SHA;
-
-if (@ARGV && $ARGV[0] eq '--help') {
-       die <<AMEN ;
-Usage: cat list | $0
-   or: $0 <files and directories>
-AMEN
-}
-
-my @files = ();
-if (@ARGV) {
-       for my $in (@ARGV) {
-               if (-f $in) {
-                       push @files, $in;
-               } elsif (-d $in) {
-                       opendir D, $in or die "Cannot scan directory $in: $!\n";
-                       my @p = ();
-                       while (my $e = readdir D) {
-                               my $f = File::Spec->canonpath(File::Spec->catfile($in, $e));
-                               if ($f =~ m{\.(jpe?g|png)$}i) {
-                                       push @p, $f;
-                               }
-                       }
-                       closedir D;
-                       push @files, sort @p;
-               } else {
-                       die "$in is neither file nor directory\n";
-               }
-       }
-} else {
-       while (<STDIN>) {
-               chomp;
-               push @files, $_;
-       }
-}
-
-STDOUT->autoflush(1);
-
-my $gal = UCW::Gallery->load_config;
-my $orig_prefix = $gal->get('OrigDir');
-$orig_prefix =~ m{/$} or $orig_prefix .= '/';
-
-print "Scanning photos\n";
-my @images = ();
-foreach my $f (@files) {
-       my $rel_name = $f;
-       if (substr($rel_name, 0, length $orig_prefix) eq $orig_prefix) {
-               $rel_name = substr($rel_name, length $orig_prefix);
-       }
-       print "\t$rel_name: ";
-
-       my $sha = Digest::SHA->new(1);
-       $sha->addfile($f) or die "Cannot hash $f\n";
-       my $id = substr($sha->hexdigest, 0, 16);
-       print "id=$id ";
-
-       my $e = new Image::EXIF($f);
-       my $i = $e->get_all_info();
-       if ($e->error) { print "EXIF error: ", $e->error, "\n"; }
-       else {
-               # print STDERR Dumper($i), "\n";
-               my $o = $i->{'image'}->{'Image Orientation'} || "Top, Left-Hand";
-               if ($o eq "Top, Left-Hand") { $o = "."; }
-               elsif ($o eq "Right-Hand, Top") { $o = "r"; }
-               elsif ($o eq "Left-Hand, Bottom") { $o = "l"; }
-               elsif ($o eq "Bottom, Right-Hand") { $o = "d"; }
-               else {
-                       print "Unrecognized orientation: $o\n";
-                       $o = ".";
-               }
-               push @images, {
-                       file => $rel_name,
-                       id => $id,
-                       orientation => $o,
-                       xfrm => $gal->get('ScanDefaultTransform'),
-                       title => '',
-               };
-               print "ori=$o\n";
-       }
-}
-
-my $old = $gal->read_list('gallery.list');
-if ($old) {
-       print "Updating gallery.list\n";
-       my %old_by_id = map { $_->{id} => $_ } @$old;
-       for my $i (@images) {
-               my $id = $i->{id};
-               my $o = $old_by_id{$id};
-               if ($o) {
-                       print "\t$id: updated\n";
-                       $i->{orientation} = $o->{orientation};
-                       $i->{xfrm} = $o->{xfrm};
-                       $i->{title} = $o->{title};
-               } else {
-                       print "\t$id: new\n";
-               }
-               delete $old_by_id{$id};
-       }
-       for my $id (keys %old_by_id) {
-               print "\t$id: removed\n";
-       }
-}
-
-$gal->write_list('gallery.list', \@images);
-print "Written gallery.list (", (scalar @images), " items)\n";