Lines starting with "#" are ignored.
-Photo meta-data (gallery.meta in PhotoDir)
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Photo meta-data (PhotoDir/gallery.meta or CacheDir/cache.meta)
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Perl Storable containing a single hash.
$meta->{photo}->{$identifier} is a hash of:
xf transformation applied
w width after scaling
h height after scaling
+ title photo title
+
+$meta->{sequence} is an array of photo IDs as they appear in the gallery.
+
+[CacheDir only]
+$meta->{thumb}->{$format}->{$identifier} is a hash of:
+ w thumbnail width
+ h thumbnail height
$CF{'MetaDataDir'} = '.',
$CF{'PhotoDir'} = '.',
- $CF{'ScanDefaultTransform'} = 'n';
+ $CF{'ScanDefaultTransform'} = 's';
$CF{'OrigDir'} = '.';
$CF{'PhotoDir'} = 'photo';
- $CF{'CacheDir'} = "cache",
+ $CF{'CacheDir'} = 'cache',
$CF{'PhotoMaxWidth'} = 1024,
$CF{'PhotoMaxHeight'} = 1024,
+ # FIXME: ThumbSizes should be set by themes
+ $CF{'ThumbSizes'} = [ [114,94], [256,256] ],
}
sub LoadConfig() {
--- /dev/null
+#!/usr/bin/perl
+# UCW Gallery: Prepare cache
+# (c) 2004--2012 Martin Mares <mj@ucw.cz>
+
+use strict;
+use warnings;
+
+use lib '/home/mj/web/gal2';
+use UCW::Gallery;
+
+use Image::Magick;
+use IO::Handle;
+use File::Spec;
+use File::Path;
+
+STDOUT->autoflush(1);
+
+UCW::Gallery::LoadConfig;
+
+my $photo_dir = $UCW::Gallery::CF{'PhotoDir'};
+my $photo_meta = File::Spec->catfile($photo_dir, 'gallery.meta');
+print "Reading meta-data from $photo_meta\n";
+-f $photo_meta or die "Cannot load $photo_meta\n";
+my $meta = UCW::Gallery::ReadMeta($photo_meta);
+
+my $cache_dir = $UCW::Gallery::CF{'CacheDir'};
+if (-d $cache_dir) {
+ print "Deleting old cache directory: $cache_dir\n";
+ File::Path::remove_tree($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 (@{$UCW::Gallery::CF{'ThumbSizes'}}) {
+ my ($tw, $th) = @$t;
+ my $thumb_fmt = $tw . 'x' . $th;
+ print "Generating $thumb_fmt thumbnails\n";
+ my $thumb_meta = {};
+ $meta->{thumb}->{$thumb_fmt} = $thumb_meta;
+ my $thumb_dir = File::Spec->catfile($cache_dir, $thumb_fmt);
+ -d $thumb_dir or File::Path::mkpath($thumb_dir) or die "Unable to create $thumb_dir: $!\n";
+
+ for my $id (@{$meta->{sequence}}) {
+ my $m = $meta->{photo}->{$id} or die;
+ print "\t$id: ";
+
+ my $p = new Image::Magick;
+ my $photo = File::Spec->catfile($photo_dir, "$id.jpg");
+ my $e;
+ $e = $p->Read($photo) and die "Error reading $photo: $e";
+
+ my $w = $m->{w};
+ my $h = $m->{h};
+ if ($w > $tw) {
+ my $s = $tw / $w;
+ $w = $w * $s;
+ $h = $h * $s;
+ }
+ if ($h > $th) {
+ my $s = $th / $h;
+ $w = $w * $s;
+ $h = $h * $s;
+ }
+ $w = int($w);
+ $h = int($h);
+ print "${w}x${h} ";
+ $p->Resize(width=>$w, height=>$h);
+
+ my $out = File::Spec->catfile($thumb_dir, "$id.jpg");
+ my $tmp = "$photo.new";
+ $e = $p->Write($tmp) and die "Unable to write $tmp: $e";
+ rename $tmp, $out or die "Unable to rename $tmp to $out: $!\n";
+
+ $thumb_meta->{$id} = {
+ 'w' => $w,
+ 'h' => $h,
+ };
+
+ print "... OK\n";
+ }
+}
+
+my $cache_meta = File::Spec->catfile($cache_dir, 'cache.meta');
+print "Writing meta-data to $cache_meta\n";
+UCW::Gallery::WriteMeta($cache_meta, $meta);
use lib '/home/mj/web/gal2';
use UCW::Gallery;
-use File::Spec;
use Image::Magick;
use IO::Handle;
use File::Spec;
my $photo_dir = $UCW::Gallery::CF{'PhotoDir'};
if (-d $photo_dir) {
- print "Using existing output directory $photo_dir\n";
+ print "Using existing output directory: $photo_dir\n";
} else {
- print "Creating output directory $photo_dir\n";
+ print "Creating output directory: $photo_dir\n";
File::Path::mkpath($photo_dir) or die "Unable to create $photo_dir: $!\n";
}
$old_meta = UCW::Gallery::ReadMeta($photo_meta);
# use Data::Dumper; print "Read old meta: ", Dumper($old_meta), "\n";
}
-my $meta = { 'photo' => {} };
+my $meta = { 'photo' => {}, 'sequence' => [] };
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;