1 # Simple Photo Gallery: Thumbnail Generator
2 # (c) 2003--2004 Martin Mares <mj@ucw.cz>
4 package Gallery::Generator;
12 BEGIN { import Gallery qw(%CF); }
14 sub new() { return bless {}; }
17 print "Generating thumbnails...\n"; STDOUT->autoflush(1);
18 my $notes = $CF{'MetaDataDir'} . "/notes";
19 open NOTES, ">$notes" or die "Unable to write to notes ($notes): $!";
30 my ($this, $orig, $annot) = @_;
31 my ($base, $ext) = ($orig =~ /^(.*)\.([^.]+)$/) or die "Unable to dissect name $orig";
33 my $p = new Image::Magick;
35 my $img = $CF{"PhotoDir"} . $orig;
36 $e = $p->Read($img) and die "Error reading $img: $e";
37 my ($wo, $ho) = $p->Get('width', 'height');
38 my ($w, $h) = ($wo, $ho);
41 if ($w > $CF{"ThumbW"}) {
42 my $s = $CF{"ThumbW"} / $w;
46 if ($h > $CF{"ThumbH"}) {
47 my $s = $CF{"ThumbH"} / $h;
53 print " -> ${w}x${h} ";
54 $p->Resize(width=>$w, height=>$h);
55 my $thumb = $CF{"ThumbDir"} . "$base-thumb.jpg";
56 $e = $p->Write($thumb) and die "Unable to write $thumb: $e";
57 print NOTES "$base $w $h $wo $ho\n";