2 # (c) 2003--2012 Martin Mares <mj@ucw.cz>
12 # Standard Perl module stuff
14 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
17 @EXPORT = qw(&SetOptions);
26 OrigDir => '.', # Original images
27 PhotoDir => 'photo', # Scaled-down photos for web
28 CacheDir => 'cache', # Cache with meta-data and thumbnails
29 ThemeDir => 'gal', # Themes
32 PhotoUrlPrefix => 'photo/',
33 ThumbUrlPrefix => 'thumb/',
34 ThemeUrlPrefix => 'gal/',
36 # Processing machinery settings
37 ScanDefaultTransform => 's',
38 PhotoMaxWidth => 1024,
39 PhotoMaxHeight => 1024,
40 ThumbFormats => {}, # Set up by themes
42 # HTML output settings
43 Title => 'An Unnamed Gallery',
54 my $cfg = "./gallery.cf";
55 unless (defined do $cfg) {
57 die "Error parsing $cfg: $@";
59 die "Cannot load $cfg: $!\n";
61 die "Cannot load $cfg, check that it returns true\n";
67 while (my $o = shift @_) {
71 require $CF{'ThemeDir'} . "/$v/theme.pm";
72 UCW::Gallery::Theme::Init($CF{'ThemeUrlPrefix'} . $v);
77 sub RequireThumbnails($$) {
79 my $fmt = "${w}x${h}";
80 $CF{'ThumbFormats'}->{$fmt} = 1;
84 my ($file, $images) = @_;
85 open LIST, '>', "$file.new" or die "Cannot create $file.new: $!\n";
86 print LIST "# Image\tID\tRotate\tXform\tTitle\n";
87 for my $i (@$images) {
93 ($i->{title} eq '' ? '-' : $i->{title}),
97 rename "$file.new", $file or die "Cannot rename $file.new to $file: $!\n";
103 open LIST, '<', $file or return;
109 ($i->{file}, $i->{id}, $i->{orientation}, $i->{xfrm}, $i->{title}) = split /\t/;
110 if ($i->{title} eq '-') { $i->{title} = ""; }
118 my ($file, $meta) = @_;
119 open META, '>', "$file.new" or die "Cannot create $file.new: $!\n";
120 Storable::nstore_fd($meta, \*META);
122 rename "$file.new", $file or die "Cannot rename $file.new to $file: $!\n";
127 open META, '<', $file or die "Cannot read $file: $!\n";
128 my $meta = Storable::fd_retrieve(\*META) or die "Cannot parse $file\n";