2 # (c) 2003--2014 Martin Mares <mj@ucw.cz>
19 OrigDir => '.', # Original images
20 PhotoDir => 'photo', # Scaled-down photos for web
21 CacheDir => 'cache', # Cache with meta-data and thumbnails
24 PhotoUrlPrefix => 'photo/',
25 ThumbUrlPrefix => 'thumb/',
26 ThemeUrlPrefix => 'gal/',
28 # Processing machinery settings
29 ScanDefaultTransform => 's',
30 PhotoMaxWidth => 1024,
31 PhotoMaxHeight => 1024,
32 ThumbFormats => [ "114x94" ], # Built-in themes use the first size,
33 # but more can be generated
34 CacheExif => 0, # Cache selected EXIF meta-data
35 CacheHashes => 1, # Let gal-scan cache file hashes
37 # Titles and navigation
38 Title => 'An Unnamed Gallery',
47 return bless $self, $class;
51 my $cfg = "./gallery.cf";
53 unless (defined $self) {
55 die "Error parsing $cfg: $@";
57 die "Cannot load $cfg: $!\n";
59 die "Cannot load $cfg, check that it returns true\n";
65 ### Object methods ###
68 my ($self, $key) = @_;
69 if (exists $self->{cfg}->{$key}) {
70 my $val = $self->{cfg}->{$key};
71 defined $val or warn "Gallery: Config item $key is not set\n";
74 warn "Gallery: Config item $key does not exist\n";
80 my ($self, $key) = @_;
81 return $self->{cfg}->{$key};
86 while (my $key = shift @_) {
88 $self->{cfg}->{$key} //= $val;
94 while (my $key = shift @_) {
95 $self->{cfg}->{$key} = shift @_;
99 sub get_config_keys($) {
101 return keys %{$self->{cfg}};
104 sub write_list($$$) {
105 my ($self, $file, $images) = @_;
106 open my $fh, '>:utf8', "$file.new" or die "Cannot create $file.new: $!\n";
107 for my $i (@$images) {
113 ($i->{title} eq '' ? '-' : $i->{title}),
117 rename "$file.new", $file or die "Cannot rename $file.new to $file: $!\n";
121 my ($self, $file) = @_;
123 open my $fh, '<:utf8', $file or return;
129 ($i->{file}, $i->{id}, $i->{orientation}, $i->{xfrm}, $i->{title}) = split /\t/;
130 if ($i->{title} eq '-') { $i->{title} = ""; }
138 my ($self, $file, $meta) = @_;
139 open my $fh, '>', "$file.new" or die "Cannot create $file.new: $!\n";
140 Storable::nstore_fd($meta, $fh);
142 rename "$file.new", $file or die "Cannot rename $file.new to $file: $!\n";
146 my ($self, $file) = @_;
147 open my $fh, '<', $file or die "Cannot read $file: $!\n";
148 my $meta = Storable::fd_retrieve($fh) or die "Cannot parse $file\n";
153 sub photo_meta_name($) {
155 return File::Spec->catfile($self->get('PhotoDir'), 'gallery.meta');
158 sub cache_meta_name($) {
160 return File::Spec->catfile($self->get('CacheDir'), 'cache.meta');
163 sub thumb_fmt_to_size($$) {
164 my ($self, $fmt) = @_;
165 my ($tw, $th) = ($fmt =~ m{^(\d+)x(\d+)$}) or die "Cannot parse thumbnail format $fmt\n";
169 sub photo_file_name($$$) {
170 my ($self, $photo_meta, $id) = @_;
171 return $id . '.' . ($photo_meta->{fmt} // 'jpg');
174 sub photo_name($$$) {
175 my ($self, $photo_meta, $id) = @_;
176 return File::Spec->catfile($self->get('PhotoDir'), $self->photo_file_name($photo_meta, $id));