]> mj.ucw.cz Git - gallery.git/commitdiff
Gallery2: First attempts at web version
authorMartin Mares <mj@ucw.cz>
Sun, 23 Dec 2012 23:32:02 +0000 (00:32 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 8 Feb 2015 20:14:08 +0000 (21:14 +0100)
14 files changed:
gal2/UCW/Gallery.pm
gal2/UCW/Gallery/Web.pm [new file with mode: 0644]
gal2/gal-cache
gal2/gal-gen
gal2/nrt/back.png [new file with mode: 0644]
gal2/nrt/bot.png [new file with mode: 0644]
gal2/nrt/left.png [new file with mode: 0644]
gal2/nrt/next.png [new file with mode: 0644]
gal2/nrt/prev.png [new file with mode: 0644]
gal2/nrt/right.png [new file with mode: 0644]
gal2/nrt/style.css [new file with mode: 0644]
gal2/nrt/theme.conf [new file with mode: 0644]
gal2/nrt/theme.pm [new file with mode: 0644]
gal2/nrt/top.png [new file with mode: 0644]

index 847de01987b3b1f226424ed13e483743111ff5cf..f0a1e97ccb01cd11f69f94793d4cf481ab6d084a 100644 (file)
@@ -20,9 +20,9 @@ BEGIN {
 }
 
 our %CF;
-our $th;
 
 BEGIN {
+       # FIXME: Check config
        $CF{'Title'} = 'An Unnamed Gallery',
        $CF{'HeadExtras'} = "",
        $CF{'TopExtras'} = "",
@@ -36,6 +36,7 @@ BEGIN {
        $CF{'ThumbUrlPrefix'} = "",
        $CF{'MetaDataDir'} = '.',
        $CF{'PhotoDir'} = '.',
+       # FIXME: Who sets GalDir?
 
        $CF{'ScanDefaultTransform'} = 's';
        $CF{'OrigDir'} = '.';
@@ -43,8 +44,7 @@ BEGIN {
        $CF{'CacheDir'} = 'cache',
        $CF{'PhotoMaxWidth'} = 1024,
        $CF{'PhotoMaxHeight'} = 1024,
-       # FIXME: ThumbSizes should be set by themes
-       $CF{'ThumbSizes'} = [ [114,94], [256,256] ],
+       $CF{'ThumbFormats'} = {},
 }
 
 sub LoadConfig() {
@@ -66,11 +66,17 @@ sub SetOptions(@) {
                $CF{$o} = $v;
                if ($o eq "Theme") {
                        require $CF{"GalDir"} . "/$v/theme.pm";
-                       Gallery::Theme::Init($CF{"GalURL"} . "/$v");
+                       UCW::Gallery::Theme::Init($CF{"GalURL"} . "/$v");
                }
        }
 }
 
+sub RequireThumbnails($$) {
+       my ($w, $h) = @_;
+       my $fmt = "${w}x${h}";
+       $CF{'ThumbFormats'}->{$fmt} = 1;
+}
+
 sub WriteList($$) {
        my ($file, $images) = @_;
        open LIST, '>', "$file.new" or die "Cannot create $file.new: $!\n";
diff --git a/gal2/UCW/Gallery/Web.pm b/gal2/UCW/Gallery/Web.pm
new file mode 100644 (file)
index 0000000..ac33361
--- /dev/null
@@ -0,0 +1,148 @@
+# Simple Photo Gallery: Web Interface
+# (c) 2003--2012 Martin Mares <mj@ucw.cz>
+
+package UCW::Gallery::Web;
+
+use UCW::Gallery qw(%CF);
+use UCW::CGI;
+use File::Spec;
+
+my $show_img;
+my $send_archive;
+
+my %args = (
+       'i'     => { 'var' => \$show_img, 'check' => '\d+' },
+       'a'     => { 'var' => \$send_archive }
+);
+
+our $meta;
+our $num_photos;
+
+sub new() {
+       if ($send_archive && $CF{'AllowArchives'}) {
+               # FIXME?
+               require UCW::Gallery::Archive;
+               return new UCW::Gallery::Archive($send_archive);
+       } else {
+               return bless {};
+       }
+}
+
+sub error($) {
+       print "<p style='color:red'>Bad luck, the script is broken. Sorry.\n<p>$_[0]\n";
+       print "</body></html>\n";
+}
+
+sub show_links($$$) {
+       my ($prev, $up, $next) = @_;
+       print "<p class=parent>";
+       print "<span class=back style='width: $CF{'BackW'}px; height: $CF{'BackH'}px'>";
+       print "<a href='$prev'><img src='$CF{'BackImg'}' width=$CF{'BackW'} height=$CF{'BackH'} alt='Back'></a>" if $prev ne "";
+       print "</span>\n";
+       print "<span class=fwd style='width: $CF{'FwdW'}px; height: $CF{'FwdH'}px'>";
+       print "<a href='$next'><img src='$CF{'FwdImg'}' width=$CF{'FwdW'} height=$CF{'FwdH'} alt='Forward'></a>" if $next ne "";
+       print "</span>\n";
+       print "<a href='$up'><img src='$CF{'ParentImg'}' width=$CF{'ParentW'} height=$CF{'ParentH'} alt='Up'></a>\n" if $up ne "";
+}
+
+sub html_top() {
+       my $title = UCW::CGI::html_escape($CF{"Title"});
+       print <<EOF ;
+Content-Type: text/html
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
+<html><head>
+$CF{"HeadExtras"}
+<link rel=stylesheet href="$CF{"StyleSheet"}" type="text/css" media=all>
+<title>$title</title>
+</head><body>
+$CF{"TopExtras"}
+EOF
+       $UCW::CGI::error_hook = \&error;
+}
+
+sub html_bot() {
+       print "$CF{'BotExtras'}\n</body></html>\n";
+}
+
+sub show_img() {
+       if ($show_img < 1 || $show_img > $num_photos) {
+               print "Status: 404\n";
+               html_top();
+               print "<h1>No such photo</h1>\n";
+               html_bot();
+               return;
+       }
+
+       my $id = $meta->{sequence}->[$show_img-1];
+       my $m = $meta->{photo}->{$id} or die;
+       html_top();
+
+       show_links(($show_img > 1 ? ("?i=".($show_img-1)) : ""),
+                  "?",
+                  ($show_img < $num_photos ? ("?i=".($show_img+1)) : ""));
+
+       my $t = UCW::CGI::html_escape($m->{title});
+       my $w = $m->{w};
+       my $h = $m->{h};
+       print "<h1>$t</h1>\n" if $t ne "";
+       my $img = $CF{'PhotoUrlPrefix'} . $id . ".jpg";
+       print "<p class=large><img src='$img' width=$w height=$h alt='$t'>\n";
+
+       html_bot();
+}
+
+sub show_list() {
+       html_top();
+
+       show_links($CF{'BackURL'}, $CF{'ParentURL'}, $CF{'FwdURL'});
+       print "<h1>$CF{'Title'}</h1>\n";
+       print "<h2>$CF{'SubTitle'}</h2>\n" if defined $CF{'SubTitle'};
+
+       my $thumb_fmt = $CF{'ThumbW'} . "x" . $CF{'ThumbH'};
+       my $thumb_meta = $meta->{thumb}->{$thumb_fmt} or die "No thumbnails for format $thumb_fmt found!\n";
+
+       for my $idx (1..$num_photos) {
+               my $id = $meta->{sequence}->[$idx-1];
+               my $m = $meta->{photo}->{$id} or die;
+               my $tm = $thumb_meta->{$id} or die;
+
+               my $annot = UCW::CGI::html_escape($m->{title});
+               my $tw = $tm->{w};
+               my $th = $tm->{h};
+               my $thumb = $CF{'ThumbUrlPrefix'} . "/$thumb_fmt/$id.jpg";
+               my $side_w = $CF{"ThumbW"} + 2*$CF{"InteriorMargin"};
+               my $side_h = $CF{"ThumbH"} + 2*$CF{"InteriorMargin"};
+               my $box_w = $CF{"LeftW"} + $side_w + $CF{"RightW"};
+               my $box_h = $CF{"TopH"} + $side_h + $CF{"BotH"};
+               print "<div class=thf><div class=thumb>\n";
+               print "<img src='$CF{'TopImg'}' width=$box_w height=$CF{'TopH'} alt='' class=tt>\n";
+               print "<img src='$CF{'LeftImg'}' width=$CF{'LeftW'} height=$side_h alt='' class=tl>\n";
+               my $ol = $CF{'LeftW'} + $CF{'InteriorMargin'} + int(($CF{'ThumbW'} - $tw)/2);
+               my $ot = $CF{'TopH'} + $CF{'InteriorMargin'} + int(($CF{'ThumbH'} - $th)/2);
+               my $tit = ($annot ne "") ? " title=\"$annot\"" : "";
+               my $url = ($CF{"ImageSubpages"} ? "?i=$id" : $orig);
+               print "<a href='$url'><img src='$thumb' width=$w height=$h alt='$orig'$tit class=ti style='left: ${ol}px; top: ${ot}px'></a>\n";
+               print "<img src='$CF{'RightImg'}' width=$CF{'RightW'} height=$side_h alt='' class=tr>\n";
+               print "<img src='$CF{'BotImg'}' width=$box_w height=$CF{'BotH'} alt='' class=tb>\n";
+               print "</div>\n";
+               print "</div>\n\n";
+       }
+
+       html_bot();
+}
+
+sub Dispatch() {
+       UCW::CGI::parse_args(\%args);
+       UCW::Gallery::LoadConfig();
+       $meta = UCW::Gallery::ReadMeta(File::Spec->catfile($CF{'CacheDir'}, 'cache.meta'));
+       $num_photos = scalar @{$meta->{sequence}};
+
+       if ($show_img ne "") {
+               show_img();
+       } else {
+               show_list();
+       }
+}
+
+42;
index d6ee3537987833da0b414968c739d76d156de6da..5accb3fd58dace7c14bb43e7a01f71c84f4aed70 100755 (executable)
@@ -31,9 +31,8 @@ if (-d $cache_dir) {
 print "Creating cache directory: $cache_dir\n";
 File::Path::mkpath($cache_dir) or die "Unable to create $cache_dir: $!\n";
 
-for my $t (@{$CF{'ThumbSizes'}}) {
-       my ($tw, $th) = @$t;
-       my $thumb_fmt = $tw . 'x' . $th;
+for my $thumb_fmt (keys %{$CF{'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;
index 7d244fe65edad26a85e6d9d86c8c87092f1bd067..3c1a6e98a81752dde349b14ae5816964b4d52310 100755 (executable)
@@ -41,7 +41,6 @@ for my $f (@$orig_list) {
        my $id = $f->{id};
        my $rotate = $f->{orientation};
        my $xfrm = $f->{xfrm};
-       push @{$meta->{sequence}}, $id;
        print "$id: ";
 
        my $p = new Image::Magick;
@@ -69,7 +68,10 @@ for my $f (@$orig_list) {
                'xf' => $xfrm,
                'w' => $w,
                'h' => $h,
+               'title' => $f->{title},
        };
+       $meta->{photo}->{$id} = $m;
+       push @{$meta->{sequence}}, $id;
 
        my $om = $old_meta->{photo}->{$id};
        if ($om &&
@@ -79,7 +81,6 @@ for my $f (@$orig_list) {
            $om->{h} eq $m->{h}) {
                # FIXME: Remove old images?
                print "... uptodate\n";
-               $meta->{photo}->{$id} = $om;
                next;
        }
 
@@ -121,7 +122,6 @@ for my $f (@$orig_list) {
        rename $tmp, $photo or die "Cannot rename $tmp to $photo: $!\n";
 
        print "... OK\n";
-       $meta->{photo}->{$id} = $m;
 }
 
 print "Writing meta-data\n";
diff --git a/gal2/nrt/back.png b/gal2/nrt/back.png
new file mode 100644 (file)
index 0000000..c0c4cee
Binary files /dev/null and b/gal2/nrt/back.png differ
diff --git a/gal2/nrt/bot.png b/gal2/nrt/bot.png
new file mode 100644 (file)
index 0000000..08c6683
Binary files /dev/null and b/gal2/nrt/bot.png differ
diff --git a/gal2/nrt/left.png b/gal2/nrt/left.png
new file mode 100644 (file)
index 0000000..3bd3aed
Binary files /dev/null and b/gal2/nrt/left.png differ
diff --git a/gal2/nrt/next.png b/gal2/nrt/next.png
new file mode 100644 (file)
index 0000000..72a4e39
Binary files /dev/null and b/gal2/nrt/next.png differ
diff --git a/gal2/nrt/prev.png b/gal2/nrt/prev.png
new file mode 100644 (file)
index 0000000..71e11cd
Binary files /dev/null and b/gal2/nrt/prev.png differ
diff --git a/gal2/nrt/right.png b/gal2/nrt/right.png
new file mode 100644 (file)
index 0000000..3e655dc
Binary files /dev/null and b/gal2/nrt/right.png differ
diff --git a/gal2/nrt/style.css b/gal2/nrt/style.css
new file mode 100644 (file)
index 0000000..b67b092
--- /dev/null
@@ -0,0 +1,17 @@
+.thf    { margin: 0 0 0 0; padding: 0 0 0 0; float: left; border: none; }
+.thumb  { position: relative; width: 154px; height: 134px; background-color: black; }
+.tt     { position: absolute; top: 0; left: 0; }
+.tl     { position: absolute; top: 14px; left: 0; }
+.ti     { position: absolute; }
+.tr     { position: absolute; top: 14px; right: 0; }
+.tb     { position: absolute; bottom: 0; right: 0; }
+.annot  { width: 154px; text-align: center; }
+IMG     { border: none; }
+H1      { text-align: center; }
+H2      { text-align: center; }
+P      { clear: both; }
+H2     { clear: both; }
+.parent        { text-align: center; }
+.large { text-align: center; }
+.back  { float: left; }
+.fwd   { float: right; }
diff --git a/gal2/nrt/theme.conf b/gal2/nrt/theme.conf
new file mode 100644 (file)
index 0000000..4242eba
--- /dev/null
@@ -0,0 +1,40 @@
+
+PicturesPerRow: 5
+BGColor: #ffffff
+TextColor: #000000
+CommentColor: #000000
+FilmBGColor: #322207
+LinkColor: #000000
+ALinkColor: gold
+VLinkColor: #000000
+LinkSize: 1
+
+#                   linksize               | top
+#                       |                  v
+#     ------------------|---------------- ---
+#     |                 |               |  |
+#     ------------------v---------------- ---
+#     |   | ______________________  |   |  ^
+#     |   | |   ^                 | |   |  |
+#     |   | |   | height          | |   |
+#     |   | |   |                 | |   |
+#  l  |   | |   |                 | |   | right
+# --->|---| |<--|----width------->| |---|<-----
+#     |   | |   |                 | |   |
+#     |   | |   |                 | |   |
+#     |   | |   |                 | |   |
+#     |   | |   v                 | |   |
+#     |   | |---------------------| |   |  |
+#     |   |                         |   |  v
+#     ----------------------------------- ---
+#     |                                 |  |
+#     ----------------------------------- ---
+#                                          ^
+#                                          | bottom
+#
+# total = left + linksize + width + linksize + right
+
+# Decorations: top bottom left right
+Decorations: 14 18 14 18
+ThumbWidth: 120
+ThumbHeight: 100
diff --git a/gal2/nrt/theme.pm b/gal2/nrt/theme.pm
new file mode 100644 (file)
index 0000000..f9674ad
--- /dev/null
@@ -0,0 +1,40 @@
+# NRT Theme for MJ's Photo Gallery
+# (c) 2003--2004 Martin Mares <mj@ucw.cz>; GPL'ed
+# Theme images taken from the cthumb package (c) Carlos Puchol
+
+package UCW::Gallery::Theme;
+
+use strict;
+use warnings;
+
+use UCW::Gallery;
+
+sub Init($) {
+       my ($u) = @_;
+       UCW::Gallery::SetOptions(
+               "StyleSheet" => "$u/style.css",
+               "ThumbW" => 114,
+               "ThumbH" => 94,
+               "TopImg" => "$u/top.png",
+               "TopH" => 14,
+               "BotImg" => "$u/bot.png",
+               "BotH" => 18,
+               "LeftImg" => "$u/left.png",
+               "LeftW" => 14,
+               "RightImg" => "$u/right.png",
+               "RightW" => 18,
+               "InteriorMargin" => 4,
+               "ParentImg" => "$u/back.png",
+               "ParentH" => 48,
+               "ParentW" => 48,
+               "BackImg" => "$u/prev.png",
+               "BackH" => 48,
+               "BackW" => 48,
+               "FwdImg" => "$u/next.png",
+               "FwdH" => 48,
+               "FwdW" => 48
+       );
+       UCW::Gallery::RequireThumbnails(114, 94);
+}
+
+1;
diff --git a/gal2/nrt/top.png b/gal2/nrt/top.png
new file mode 100644 (file)
index 0000000..d8d5866
Binary files /dev/null and b/gal2/nrt/top.png differ