2 # (c) 2003--2012 Martin Mares <mj@ucw.cz>
18 OrigDir => '.', # Original images
19 PhotoDir => 'photo', # Scaled-down photos for web
20 CacheDir => 'cache', # Cache with meta-data and thumbnails
23 PhotoUrlPrefix => 'photo/',
24 ThumbUrlPrefix => 'thumb/',
25 ThemeUrlPrefix => 'gal/',
27 # Processing machinery settings
28 ScanDefaultTransform => 's',
29 PhotoMaxWidth => 1024,
30 PhotoMaxHeight => 1024,
31 ThumbFormats => [ "114x94" ], # Built-in themes use the first size,
32 # but more can be generated
34 # Titles and navigation
35 Title => 'An Unnamed Gallery',
41 return bless $self, $class;
45 my $cfg = "./gallery.cf";
47 unless (defined $self) {
49 die "Error parsing $cfg: $@";
51 die "Cannot load $cfg: $!\n";
53 die "Cannot load $cfg, check that it returns true\n";
59 ### Object methods ###
62 my ($self, $key) = @_;
63 if (exists $self->{cfg}->{$key}) {
64 my $val = $self->{cfg}->{$key};
65 defined $val or warn "Gallery: Config item $key is not set\n";
68 warn "Gallery: Config item $key does not exist\n";
75 while (my $key = shift @_) {
77 $self->{cfg}->{$key} //= $val;
83 while (my $key = shift @_) {
84 $self->{cfg}->{$key} = shift @_;
88 sub get_config_keys($) {
90 return keys %{$self->{cfg}};
94 my ($self, $file, $images) = @_;
95 open my $fh, '>:utf8', "$file.new" or die "Cannot create $file.new: $!\n";
96 for my $i (@$images) {
102 ($i->{title} eq '' ? '-' : $i->{title}),
106 rename "$file.new", $file or die "Cannot rename $file.new to $file: $!\n";
110 my ($self, $file) = @_;
112 open my $fh, '<:utf8', $file or return;
118 ($i->{file}, $i->{id}, $i->{orientation}, $i->{xfrm}, $i->{title}) = split /\t/;
119 if ($i->{title} eq '-') { $i->{title} = ""; }
127 my ($self, $file, $meta) = @_;
128 open my $fh, '>', "$file.new" or die "Cannot create $file.new: $!\n";
129 Storable::nstore_fd($meta, $fh);
131 rename "$file.new", $file or die "Cannot rename $file.new to $file: $!\n";
135 my ($self, $file) = @_;
136 open my $fh, '<', $file or die "Cannot read $file: $!\n";
137 my $meta = Storable::fd_retrieve($fh) or die "Cannot parse $file\n";
142 sub photo_meta_name($) {
144 return File::Spec->catfile($self->get('PhotoDir'), 'gallery.meta');
147 sub cache_meta_name($) {
149 return File::Spec->catfile($self->get('CacheDir'), 'cache.meta');
152 sub thumb_fmt_to_size($$) {
153 my ($self, $fmt) = @_;
154 my ($tw, $th) = ($fmt =~ m{^(\d+)x(\d+)$}) or die "Cannot parse thumbnail format $fmt\n";