]> mj.ucw.cz Git - gallery.git/blob - gal/gal-merge
Temporary move to gal/, so that we can import history from mj-web
[gallery.git] / gal / gal-merge
1 #!/usr/bin/perl
2 # Merge photos from multiple sources
3 # (c) 2008 Martin Mares <mj@ucw.cz>
4
5 use Image::EXIF;
6 use Data::Dumper;
7
8 use strict;
9 use warnings;
10
11 my @pics = ();
12 if (@ARGV) {
13         @pics = @ARGV;
14 } else {
15         while (<STDIN>) {
16                 chomp;
17                 /^#/ && next;
18                 /^$/ && next;
19                 push @pics, $_;
20         }
21 }
22
23 my %seen = ();
24 foreach my $f (@pics) {
25         my $e = new Image::EXIF($f);
26         my $i = $e->get_all_info();
27         if ($e->error) { print STDERR "EXIF error on $f: ", $e->error, "\n"; }
28         else {
29                 #print STDERR Dumper($i), "\n";
30                 my $o = $i->{'image'}->{'Image Orientation'} || "Top, Left-Hand";
31                 if ($o eq "Top, Left-Hand") { $o = "."; }
32                 elsif ($o eq "Right-Hand, Top") { $o = "r"; }
33                 elsif ($o eq "Left-Hand, Bottom") { $o = "l"; }
34                 elsif ($o eq "Bottom, Right-Hand") { $o = "d"; }
35                 else {
36                         print STDERR "Unrecognized orientation: $o\n";
37                         $o = ".";
38                 }
39                 my $d = $i->{'image'}->{'Image Created'};
40                 if (defined($d)) {
41                         $d =~ s/^(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})/$1$2$3-$4$5$6/ or die "Date parse error: $d";
42                 } else {
43                         print STDERR "Unrecognized data, skipping: $f\n";
44                         next;
45                 }
46                 my $fn = $d;
47                 if ($f =~ m{^\.\./orig/(\w+)/}) {
48                         $fn = "$fn-$1";
49                 }
50                 if (defined $seen{$fn}) {
51                         my $c = ++$seen{$fn};
52                         $fn = "$fn-$c";
53                 } else {
54                         $seen{$fn} = 1;
55                 }
56                 print "ln -s '$f' '$fn.jpg'\n";
57         }
58 }