]> mj.ucw.cz Git - gallery.git/blobdiff - gal2/bin/gal-mj-upgrade
Gallery2: gal-mj-upgrade writes thumbnail data
[gallery.git] / gal2 / bin / gal-mj-upgrade
index 6806012fd3ff68eef24c4afab75e2864e78caa19..66c260fd65adb35b17765fefafb5cb386560205b 100755 (executable)
@@ -5,6 +5,7 @@ use warnings;
 
 use UCW::Gallery;
 use File::Spec;
+use Image::Magick;
 
 my $photos_root = $ENV{HOME} . '/photos';
 
@@ -61,6 +62,7 @@ if (open S, "../static/photos/$album/x") {
 
 open I, "$album/index.cgi" or die "Cannot find $album/index.cgi\n";
 open W, ">$album/gallery.new" or die "Cannot create $album/gallery.new\n";
+open T, ">$album/gallery.thumb" or die "Cannot create $album/gallery.thumb\n";
 my %opt = ();
 my %found_dirs = ();
 my @items = ();
@@ -69,10 +71,11 @@ while (<I>) {
        if (/^\s+"(\w+)" => "(.*)",?$/) {
                $opt{$1} = $2;
                print "Option: $1 = $2\n";
-       } elsif (/^img\("([^"]+)\.jpe?g", "([^"]*)"\);\s*# (\S+)/) {
+       } elsif (/^img\("([^"]+)(\.jpe?g)", "([^"]*)"\);\s*# (\S+)/) {
                my $nr = $1;
-               my $title = $2;
-               my $file = $3;
+               my $ext = $2;
+               my $title = $3;
+               my $file = $4;
                $file =~ s{^.*/}{}g;
 
                my $map = $map{$file};
@@ -101,12 +104,24 @@ while (<I>) {
                        ($src ? $src->{xform} : '.'),
                        ($title ne "" ? $title : '-'),
                        ), "\n";
+
+
+               my $thumb = "../static/photos/$album/$nr-thumb.jpg";
+               if (!-f $thumb) {
+                       print STDERR "$album: Cannot find thumbnail for photo $nr ($thumb)\n";
+                       print T "1 1\n";
+               } else {
+                       my $im = new Image::Magick;
+                       my ($thumb_w, $thumb_h, $thumb_size, $thumb_format) = $im->PingImage($thumb) or die "Error reading $thumb\n";
+                       print T "$thumb $thumb_w $thumb_h\n";
+               }
        } elsif (/^($|#|require|SetOptions|\)|Start|Finish)/) {
                # Nothing important
        } else {
                print STDERR "$album/index.cgi: Parse error at line $.: $_\n";
        }
 }
+close T;
 close W;
 close I;