From 563a97a063d93510ef805d10866371c19059b3c3 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 29 Dec 2012 17:59:50 +0100 Subject: [PATCH] Gallery2: gal-mj-upgrade writes thumbnail data --- gal2/bin/gal-mj-upgrade | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/gal2/bin/gal-mj-upgrade b/gal2/bin/gal-mj-upgrade index 6806012..66c260f 100755 --- a/gal2/bin/gal-mj-upgrade +++ b/gal2/bin/gal-mj-upgrade @@ -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 () { 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 () { ($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; -- 2.39.2