o gallery.cf -- all programs expect that the current directory contains
a configuration file. In fact, the config file is a perl script, whose
sole purpose is to set up paths, construct a gallery object and set its
- options. Also, it usually attaches an appropriate web front-end.
+ options.
A simple example looks as follows:
use UCW::Gallery;
- use UCW::Gallery::Web::Plain;
my $gal = UCW::Gallery->new;
- UCW::Gallery::Web::Plain->attach($gal);
-
$gal->set(Title => 'A Gallery', SubTitle => '(an example)');
return $gal;
use lib "../path/to/gallery/modules";
use UCW::Gallery;
+ use UCW::Gallery::Web::Plain;
my $gal = UCW::Gallery->load_config();
- $gal->get('WebFe')->dispatch();
+ UCW::Gallery::Web::Plain->run($gal);
Workflow
~~~~~~~~
ScanDefaultTransform => 's',
PhotoMaxWidth => 1024,
PhotoMaxHeight => 1024,
- ThumbFormats => {}, # Set up by themes
+ ThumbFormats => [ "114x94" ], # Built-in themes use the first size,
+ # but more can be generated
# Titles and navigation
Title => 'An Unnamed Gallery',
my $self = shift;
while (my $key = shift @_) {
my $val = shift @_;
- !exists $self->{cfg}->{$key} or warn "Gallery: Re-definining config item $key\n";
- $self->{cfg}->{$key} = $val;
+ $self->{cfg}->{$key} //= $val;
}
}
sub set($@) {
my $self = shift;
while (my $key = shift @_) {
- my $val = shift @_;
- exists $self->{cfg}->{$key} or warn "Gallery: Config item $key does not exist\n";
- $self->{cfg}->{$key} = $val;
+ $self->{cfg}->{$key} = shift @_;
}
}
return keys %{$self->{cfg}};
}
-sub require_thumbnails($$$) {
- my ($self, $w, $h) = @_;
- my $fmt = "${w}x${h}";
- $self->{cfg}->{ThumbFormats}->{$fmt} = 1;
- return $fmt;
-}
-
sub write_list($$$) {
my ($self, $file, $images) = @_;
open my $fh, '>:utf8', "$file.new" or die "Cannot create $file.new: $!\n";
return File::Spec->catfile($self->get('CacheDir'), 'cache.meta');
}
+sub thumb_fmt_to_size($$) {
+ my ($self, $fmt) = @_;
+ my ($tw, $th) = ($fmt =~ m{^(\d+)x(\d+)$}) or die "Cannot parse thumbnail format $fmt\n";
+ return ($tw, $th);
+}
+
1;
our @ISA = qw(UCW::Gallery::Web);
my $theme_name = "plain";
-my $navw = 48;
-my $navh = 48;
-my $box_w = 130;
-my $box_h = 110;
-my $thumb_w = 114;
-my $thumb_h = 94;
sub theme_dir($) {
my ($self) = @_;
sub theme_head_extras($) {
my ($self) = @_;
- my $tdir = $self->theme_dir;
my $hsdir = $self->get('ThemeUrlPrefix') . "highslide";
return <<AMEN ;
-<link rel=stylesheet href='$tdir/style.css' type='text/css' media=all>
<script type="text/javascript" src="$hsdir/highslide-with-gallery.js"></script>
<script type="text/javascript" src="$hsdir/custom.js" charset="utf-8"></script>
<script type="text/javascript">
my ($self, $prev, $up, $next) = @_;
my $theme = $self->theme_dir;
print "<p class=parent>";
- print "<span class=back style='width: ${navw}px; height: ${navh}px'>";
- print "<a href='$prev'><img src='$theme/prev.png' width=${navw} height=${navh} alt='Back'></a>" if $prev ne "";
- print "</span>\n";
- printf "<span class=fwd style='width: ${navw}px; height: ${navh}px'>";
- printf "<a href='$next'><img src='$theme/next.png' width=${navw} height=${navh} alt='Forward'></a>" if $next ne "";
- print "</span>\n";
- printf "<a href='$up'><img src='$theme/back.png' width=${navw} height=${navh} alt='Up'></a>" if $up ne "";
+ print "<a href='$prev'><img class=back prev src='$theme/prev.png'></a>" if $prev ne "";
+ printf "<a href='$next'><img class=fwd src='$theme/next.png'></a>" if $next ne "";
+ printf "<a href='$up'><img class=up src='$theme/back.png'></a>" if $up ne "";
}
sub show_pre_thumbs($) {
sub show_thumb($) {
my ($self, $meta, $photo_id, $click_url) = @_;
- my $theme = $self->theme_dir;
my $m = $meta->{photo}->{$photo_id};
my $annot = UCW::CGI::html_escape($m->{title});
- my $tf = $self->{thumb_fmt};
+ my $tf = $self->get('ThumbFormats')->[0];
my $tm = $meta->{thumb}->{$tf}->{$photo_id} or die "No thumbnails for format $tf found!\n";
my $tw = $tm->{w};
my $th = $tm->{h};
print "<img src='$thumb' width=$tw height=$th alt='Photo'$tit></a>\n";
}
-sub attach($$) {
+sub run($$) {
my ($class, $gal) = @_;
my $self = $class->SUPER::attach($gal);
- $self->{thumb_fmt} = $gal->require_thumbnails($thumb_w, $thumb_h);
+ $self->dispatch();
return $self;
}
my $theme_name = "nrt-blue";
my $navw = 48;
my $navh = 48;
-my $thumb_w = 114;
-my $thumb_h = 94;
my $interior_margin = 4;
my $left_w = 14;
my $right_w = 18;
my $theme = $self->theme_dir;
my $m = $meta->{photo}->{$photo_id};
my $annot = UCW::CGI::html_escape($m->{title});
- my $tf = $self->{thumb_fmt};
+ my $tf = $self->get('ThumbFormats')->[0];
+ my ($thumb_w, $thumb_h) = $self->{gal}->thumb_fmt_to_size($tf);
my $tm = $meta->{thumb}->{$tf}->{$photo_id} or die "No thumbnails for format $tf found!\n";
my $tw = $tm->{w};
my $th = $tm->{h};
print "</div></div>\n\n";
}
-sub attach($$) {
+sub run($$) {
my ($class, $gal) = @_;
my $self = $class->SUPER::attach($gal);
- $self->{thumb_fmt} = $gal->require_thumbnails($thumb_w, $thumb_h);
+ $self->dispatch();
return $self;
}
my $navh = 48;
my $box_w = 130;
my $box_h = 110;
-my $thumb_w = 114;
-my $thumb_h = 94;
sub theme_dir($) {
my ($self) = @_;
my $theme = $self->theme_dir;
my $m = $meta->{photo}->{$photo_id};
my $annot = UCW::CGI::html_escape($m->{title});
- my $tf = $self->{thumb_fmt};
+ my $tf = $self->get('ThumbFormats')->[0];
+ my ($thumb_w, $thumb_h) = $self->{gal}->thumb_fmt_to_size($tf);
my $tm = $meta->{thumb}->{$tf}->{$photo_id} or die "No thumbnails for format $tf found!\n";
my $tw = $tm->{w};
my $th = $tm->{h};
print "</div></div>\n\n";
}
-sub attach($$) {
+sub run($$) {
my ($class, $gal) = @_;
my $self = $class->SUPER::attach($gal);
- $self->{thumb_fmt} = $gal->require_thumbnails($thumb_w, $thumb_h);
+ $self->dispatch();
return $self;
}
$m->{title} = $f->{title};
}
-for my $thumb_fmt (keys %{$gal->get('ThumbFormats')}) {
- my ($tw, $th) = ($thumb_fmt =~ m{^(\d+)x(\d+)$}) or die "Cannot parse thumbnail format $thumb_fmt\n";
+for my $thumb_fmt (@{$gal->get('ThumbFormats')}) {
print "Generating $thumb_fmt thumbnails\n";
+ my ($tw, $th) = $gal->thumb_fmt_to_size($thumb_fmt);
my $thumb_meta = {};
$meta->{thumb}->{$thumb_fmt} = $thumb_meta;
my $thumb_dir = File::Spec->catfile($cache_dir, $thumb_fmt);