]> mj.ucw.cz Git - gallery.git/commitdiff
Cleaned up gal-gen
authorMartin Mares <mj@ucw.cz>
Sun, 2 Feb 2014 23:20:52 +0000 (00:20 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 8 Feb 2015 20:14:17 +0000 (21:14 +0100)
gal/FORMAT
gal/README
gal/bin/gal-gen

index 55ddd0daac9e39c5a26f485e283b9d5ae56b50cc..e0f776a4b3db888b748189514c1493129f2dcdbd 100644 (file)
@@ -23,6 +23,7 @@ $meta->{photo}->{$identifier} is a hash of:
        xf              transformation applied
        w               width after scaling
        h               height after scaling
+       w0, h0          width and height of original image
        title           photo title
        fmt             photo format (png/jpg; defaults to jpg)
 
index e37fda09c1a9a65ee91b0e8c5e0c81ef6f01b207..893a6e5e41ef8211544be29a756f88d16c7a09bc 100644 (file)
@@ -2,7 +2,7 @@
 
                               UCW::Gallery v2.0
 
-                   (c) 2004--2012 Martin Mares <mj@ucw.cz>
+                   (c) 2004--2014 Martin Mares <mj@ucw.cz>
 
 ================================================================================
 
@@ -16,6 +16,7 @@ Perl with the following non-core modules:
 
    o  UCW::CGI (see http://www.ucw.cz/libucw/)
    o  Image::Magick
+   o  Image::Exif
    o  Archive::Zip
    o  Digest::SHA
 
index 2a1e0caa0b4ada805babf8f345b7bb71a6f922b3..22a38baa51aedf8b06e02c431537ea61aeaf487b 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 # UCW Gallery: Generate published photos
-# (c) 2004--2012 Martin Mares <mj@ucw.cz>
+# (c) 2004--2014 Martin Mares <mj@ucw.cz>
 
 use strict;
 use warnings;
@@ -34,15 +34,11 @@ if (-f $photo_meta) {
 }
 my $meta = { 'photo' => {} };
 
-for my $f (@$orig_list) {
-       my $id = $f->{id};
+sub get_meta_basic($$$) {
+       my ($f, $m, $p) = @_;
        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";
+       my ($orig_w, $orig_h, $orig_size, $orig_format) = $p->PingImage($f->{orig}) or die "Error reading " . $f->{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);
@@ -60,29 +56,23 @@ for my $f (@$orig_list) {
        $w = int($w + .5);
        $h = int($h + .5);
        
-       my $m = {
-               'o' => $rotate,
-               'xf' => $xfrm,
-               'w' => $w,
-               'h' => $h,
-       };
-       $meta->{photo}->{$id} = $m;
+       $m->{o} = $rotate;
+       $m->{xf} = $f->{xfrm};
+       $m->{w0} = $w0;
+       $m->{h0} = $h0;
+       $m->{w} = $w;
+       $m->{h} = $h;
+}
 
-       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}) {
-               print "... uptodate\n";
-               next;
-       }
+sub generate_photo($$$) {
+       my ($f, $m, $p) = @_;
 
        my $e;
-       $e = $p->Read($orig) and die "Error reading $orig: $e";
+       $e = $p->Read($f->{orig}) and die "Error reading " . $f->{orig} . ": $e";
        $p->Strip;
        $p->SetAttribute(quality=>90);
 
+       my $xfrm = $m->{xf};
        if ($xfrm =~ /s/) {
                print "-> sharpen ";
                $p->Sharpen(1);
@@ -96,6 +86,7 @@ for my $f (@$orig_list) {
                $p->Normalize();
        }
 
+       my $rotate = $m->{o};
        my $rot = 0;
        if ($rotate eq "l") { $rot = 270; }
        elsif ($rotate eq "r") { $rot = 90; }
@@ -105,16 +96,40 @@ for my $f (@$orig_list) {
                $p->Rotate(degrees=>$rot);
        }
 
-       if ($w != $w0 || $h != $h0) {
+       my ($w, $h) = ($m->{w}, $m->{h});
+       if ($w != $m->{w0} || $h != $m->{h0}) {
                print "-> ${w}x${h} ";
                $p->Resize(width=>$w, height=>$h);
        }
 
-       my $photo = $gal->photo_name($m, $id);
+       my $photo = $gal->photo_name($m, $f->{id});
        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";
+}
+
+for my $f (@$orig_list) {
+       my $id = $f->{id};
+       print "$id: ";
+
+       my $m = { };
+       $meta->{photo}->{$id} = $m;
+       $f->{orig} = File::Spec->rel2abs($f->{file}, $gal->get('OrigDir'));
+
+       my $p = new Image::Magick;
+       get_meta_basic($f, $m, $p);
+
+       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}) {
+               print "... uptodate\n";
+               next;
+       }
 
+       generate_photo($f, $m, $p);
        print "... OK\n";
 }
 
@@ -130,3 +145,4 @@ for my $f (<$photo_dir/*.jpg>) {
 
 print "Writing meta-data\n";
 $gal->write_meta($photo_meta, $meta);
+exit 0;