2 # Generate image gallery
3 # (c) 2004--2007 Martin Mares <mj@ucw.cz>
5 # Syntax of input file:
6 # <filename> <datestamp> <rotation> <xform>
7 # where <rotation> is either ".", "l", "r" or "u"
9 # d touch output file to <datestamp>
10 # D include <datestamp> in output file names
11 # n normalize contrast
13 # h equalize histogram
26 print STDERR "Searching for template file... ";
32 my $t = "${tdir}gallery.cf";
41 print STDERR "$templ\n";
43 print STDERR "NONE\n";
46 print "#!/usr/bin/perl\n\n";
48 print "require \"$templ\";\n\n";
49 print "SetOptions(\n";
52 use lib '/home/mj/WWW/gal';
56 "GalURL" => "/~mj/gal",
57 "GalDir" => "/home/mj/WWW/gal",
69 #`rm -f [0-9]*.{jpg,png} *.tmp`; $? && die;
74 my ($src, $date, $rotate, $xform) = split (/\t+/, $_);
76 my $id = sprintf("%03d", $idx);
83 if ($src =~ /\.(jpg|JPG|jpeg)$/) {
86 } elsif ($src =~ /\.png$/) {
89 die "$src: Unknown image type";
91 my $tmp = "$dest.tmp";
92 print STDERR "$dest: $src ";
94 my $p = new Image::Magick;
96 $e = $p->Read($src) and die "Error reading $tmp: $e";
98 $p->SetAttribute(quality=>90);
99 my ($w, $h) = $p->Get('width', 'height');
100 print STDERR "-> ${w}x${h} ";
102 my ($w0, $h0) = ($rotate eq "l" || $rotate eq "r") ? ($h, $w) : ($w, $h);
103 my ($ww, $hh) = ($w0, $h0);
120 $ww != $w0 || $hh != $h0) {
122 if ($rotate eq "l") { $rot = 270; }
123 elsif ($rotate eq "r") { $rot = 90; }
124 elsif ($rotate eq "u") { $rot = 180; }
126 print STDERR "-> sharpen ";
130 print STDERR "-> equalize ";
134 print STDERR "-> normalize ";
138 print STDERR "-> rotate $rot ";
139 $p->Rotate(degrees=>$rot);
142 if ($ww != $w0 || $hh != $h0) {
143 print STDERR "-> ${ww}x${hh} ";
144 $p->Resize(width=>$ww, height=>$hh);
146 $e = $p->Write($tmp) and die "Unable to write $tmp: $e";
148 `cp $src $tmp`; $? && die;
152 my $tran = "-optimize -copy none";
153 if ($rotate eq ".") { }
154 elsif ($rotate eq "l") { $tran .= " -rotate 270 -trim"; }
155 elsif ($rotate eq "r") { $tran .= " -rotate 90 -trim"; }
156 elsif ($rotate eq "u") { $tran .= " -rotate 180 -trim"; }
157 else { die "Unknown rotation type $rotate"; }
158 print STDERR "-> $tran ";
159 `jpegtran $tran <$tmp >$dest`; $? && die;
161 rename $tmp, $dest or die;
165 `touch -d "$date" $dest`; die if $?;
169 print STDERR "... OK\n";
170 print "img(\"$dest\", \"\");\t\t# $src (${w0}x${h0})\n";
175 `rm -f *.tmp`; $? && die;