Here's a patch
Terry Gliedt <[email protected]> Sun, 11 May 2003 16:18:04 -0400
| Newsgroups | gmane.comp.web.cthumb.devel |
|---|---|
| Message-ID | <[email protected]> |
The attached is a patch (done the correct way, I hope) that does the
following:
(1) One complaint I've had is all the trash cthumb puts in my images
directory. So I thought I'd add a directive so you can push the
thumbnails and html (all but the top level HTML) in a subdirectory.
After plowing through the code I discovered that it's already been
done. Just never documented (another complaint) and used a hardcoded
path 'thumb'. So I added a directive 'CthumbDir' and let it default to
'.'. However if you do provide a CthumbDir value, it creates the
subdirectory. The code already there does what I want - puts all the
trash someone else.
In testing this I found two opens that did not check if they worked and
blindly went on generating hundreds of Perl errors. I added checks if
they fail and stop -- also telling me what file it was trying to open
(so I could fix my bug). I did not look for ignored opens elsewhere
(another complaint about the code). Someday I might attack these sorts
of things.
(2) Added support so the title and comment lines can be continued in the
album file. This avoids overly long lines the album file. Of course
this meant I had to truncate these lines in some places (who wants an
HTML page with a title that is 500 characters long?) For example:
Page: index
Pictures from Tom's Trip<br><font size=2>\
<a href=originals>Original Pictures</a></font>
- 01.1.jpg
Oct 79, Minneapolis Airport. Notice how many people \
are on the airplane. See the person in the blue shirt? \
This is the person we were looking for.
Anyway, this results in a paragraph being constructed under the
thumbnail or picture. Sometimes this is good, sometimes not. But now it
is at least possible.
And finally, a promise I intend to keep. DOCUMENTATION. I have a small
collection of HTML pages with examples of how to use cthumb in simple
and more complex cases. I have yet to write the pages on
'customization'. .. that's going to require more work on my part to
figure out what the heck DOES happen.
cthumb.patch.1
(text/plain, 7.9 KB)
*** /home/tpg/src/cthumb-4.2/cthumb.in 2002-08-13 13:24:05.000000000 -0400
--- c 2003-05-11 15:29:51.000000000 -0400
***************
*** 28,35 ****
use Getopt::Std;
! my $version = "@cthumb_version@";
! my $prefix = "@prefix@";
############################
# public variables
--- 28,35 ----
use Getopt::Std;
! my $version = "4.2";
! my $prefix = "/usr/local";
############################
# public variables
***************
*** 86,94 ****
["Decorations" , "array" , "" , "0 0 0 0" , "x", "t", " ", "theme measurement"],
["InsertExif" , "boolean", "" , "0" , " ", "c", " ", "generate automatic Exif info"],
["UseMogrify" , "boolean", "" , "0" , " ", "c", " ", "use mogrify for scaling and rotating - required for image rotation"],
! ["RecursiveCP" , "string" , "" , "@CPR@" , " ", "x", "x", "'cp -a' for gnu cp, set to 'cp -r' for bsd, else 'rsync -avq'"],
! ["ImageDir" , "string" , "" , "@themedir@" , " ", "c", "x", "directory where themes are found"],
["HtmlExtension" , "string" , "" , "html" , " ", " ", "x", "files to create - typically html, shtml or php"],
);
############################
--- 86,95 ----
["Decorations" , "array" , "" , "0 0 0 0" , "x", "t", " ", "theme measurement"],
["InsertExif" , "boolean", "" , "0" , " ", "c", " ", "generate automatic Exif info"],
["UseMogrify" , "boolean", "" , "0" , " ", "c", " ", "use mogrify for scaling and rotating - required for image rotation"],
! ["RecursiveCP" , "string" , "" , "rsync -avqC" , " ", "x", "x", "'cp -a' for gnu cp, set to 'cp -r' for bsd, else 'rsync -avq'"],
! ["ImageDir" , "string" , "" , "${prefix}/share/images/cthumb" , " ", "c", "x", "directory where themes are found"],
["HtmlExtension" , "string" , "" , "html" , " ", " ", "x", "files to create - typically html, shtml or php"],
+ ["CthumbDir" , "string", "" , "." , " ", " ", "x", "directory where thumbnails and html are created"],
);
############################
***************
*** 145,150 ****
--- 146,152 ----
my $RecursiveCP = '';
my $ImageDir = '';
my $HtmlExtension = '';
+ my $CthumbDir = '.';
my %opt = (); # Option flags saved here
my $InsertExifUrl = ''; # For broken InsertExif code
***************
*** 239,244 ****
--- 241,257 ----
print "cthumb $version, running in $pwd\n";
+ if ($CthumbDir eq '') { $CthumbDir = '.'; } # Null means the CWD
+ else { # Else create this directory if specified
+ if (! -d $CthumbDir) {
+ if (! mkdir($CthumbDir,0755)) {
+ warn "Unable to create CthumbDir dir '$CthumbDir': $!\n";
+ $CthumbDir = '.'; # Reset this option
+ }
+ else { print "Created subdirectory '$CthumbDir'\n"; }
+ }
+ }
+
if ($opt{i}) { # image dir
$ImageDir = $opt{i};
}
***************
*** 599,611 ****
my $previous_html="";
if (! -e $fname) { # doesn't exist - create it
! open OUT, ">$fname";
! print OUT $text;
! close OUT;
! print "Creating page:\t$fname\n";
! return;
}
! open IN, "<$fname";
while (<IN>) { # suck it all in a variable
$previous_html .= $_;
}
--- 612,626 ----
my $previous_html="";
if (! -e $fname) { # doesn't exist - create it
! open(OUT, ">$fname") ||
! die "Unable to create file '$fname': $!\n";
! print OUT $text;
! close OUT;
! print "Creating page:\t$fname\n";
! return;
}
! open(IN, "<$fname") ||
! die "Unable to read file '$fname': $!\n";
while (<IN>) { # suck it all in a variable
$previous_html .= $_;
}
***************
*** 636,642 ****
$str .= " -->\n";
$str .= "</STYLE>\n";
$str .= "<title>";
! $str .= &encode_entities($title);
$str .= "</title>\n</head>\n";
$str .= "<body text=\"#000088\" bgcolor=\"$TitleBgColor\" link=\"#000033\" ";
$str .= "vlink=\"#666600\" alink=\"#ff0000\">\n";
--- 651,660 ----
$str .= " -->\n";
$str .= "</STYLE>\n";
$str .= "<title>";
! my $t = encode_entities($title);
! # Avoid overly long titles
! if (length($t) > 50) { $t = substr($t,0,50) . '...'; }
! $str .= $t;
$str .= "</title>\n</head>\n";
$str .= "<body text=\"#000088\" bgcolor=\"$TitleBgColor\" link=\"#000033\" ";
$str .= "vlink=\"#666600\" alink=\"#ff0000\">\n";
***************
*** 706,720 ****
sub thumbname {
my $pic = shift;
! # $pic =~ /^(.*?)(\.gif|\.jpg)?$/;
$pic =~ m#^(.*/)?([^/]+)\.(gif|tif+|jpe?g)$#i;
! # use thumb/ subdirectory if it already exists
! my $base = (defined($1))? $1 : '';
! if (-w ($base . "thumb")) {
! return ($base . "thumb/$2-thumb.jpg");
! } else {
! return $base . $2 . "-thumb.jpg";
! }
}
sub html_footer {
--- 724,734 ----
sub thumbname {
my $pic = shift;
! # CthumbDir is the directory where thumbnails go (thumb or '.')
$pic =~ m#^(.*/)?([^/]+)\.(gif|tif+|jpe?g)$#i;
!
! my $base = (defined($1)) ? $1 : '';
! return $base . "$CthumbDir/$2-thumb.jpg";
}
sub html_footer {
***************
*** 783,789 ****
# fill picture description and story with text from user
for my $i (1..$NLanguages) {
! $_ = <ALBUM>;
if (/^(Page|\s*[-<>] )/) {
goto top;
}
--- 797,810 ----
# fill picture description and story with text from user
for my $i (1..$NLanguages) {
! my $l = <ALBUM>;
! while ($l =~ /\\$/) { # If line ends in \, concatenate next line
! chomp($l);
! chop($l);
! $l .= <ALBUM>;
! }
! if ($l =~ /\\$/) { chomp($l); chop($l); }
! $_ = $l; # Continue with one long line
if (/^(Page|\s*[-<>] )/) {
goto top;
}
***************
*** 906,914 ****
split_filename($originalPictureURL);
my $outputPath = $path;
! if (-w "$path/thumb") {
! $outputPath .= "/thumb";
! }
my $originalPictureGeometry =
$originalPictureGeometryArray[$pictureNumber];
--- 927,933 ----
split_filename($originalPictureURL);
my $outputPath = $path;
! if ($CthumbDir ne '.') { $outputPath .= '/' . $CthumbDir; }
my $originalPictureGeometry =
$originalPictureGeometryArray[$pictureNumber];
***************
*** 1261,1268 ****
# Encoding title strips out insecure html. This is done in case someone
# wishes to run cthum inside a server.
! $str .= &encode_entities($title);
!
$str .= "</title>\n";
$str .= "</head>\n\n";
$str .= "<body ";
--- 1280,1289 ----
# Encoding title strips out insecure html. This is done in case someone
# wishes to run cthum inside a server.
! my $t = encode_entities($title);
! # Avoid overly long titles
! if (length($t) > 50) { $t = substr($t,0,50) . '...'; }
! $str .= $t;
$str .= "</title>\n";
$str .= "</head>\n\n";
$str .= "<body ";
***************
*** 1889,1895 ****
$desc =~ s/<br>/ /ig; # try to clean standard stuff
$desc =~ s/<[^>]*>//g; # try to remove other artifacts
$desc =~ s/\"/\"/g; # quote quotes
!
return $desc;
}
--- 1910,1918 ----
$desc =~ s/<br>/ /ig; # try to clean standard stuff
$desc =~ s/<[^>]*>//g; # try to remove other artifacts
$desc =~ s/\"/\"/g; # quote quotes
! # If the description is too long, shorten it
! if (length($desc) < 50) { return $desc; }
! $desc = substr($desc,0,50) . '...';
return $desc;
}