# imgsizer -- correct image sizes in WWW pages
#
# by Eric S. Raymond <esr@thyrsus.com> 30 Jul 1996
-# modified by Erik Rossen <rossen@planet.ch> 15 May 1999
+#
+# Modified by Erik Rossen <rossen@planet.ch> 15 May 1999
+#
+# Modified by Michael C. Toren <michael@toren.net> 18 Aug 2000;
+# Fixed bug where the SRC attribute needed to be in quotes, improved
+# command line argument parsing (but it could still use some work),
+# added -q switch to omit quotes when generating tags, and -l switch
+# to generate lowercase tags.
#
# Fix up IMG tags in given documents to contain correct sizes.
# No longer requires the identify(1) program from the ImageMagick suite if
# clearly mark an altered version. Fixes and enhancements cheerfully
# accepted.
#
-# This is version 1.6pre.
+# This is version 1.6pre+mct
#
# Anything that can fetch a URL defined on the command line
# and dump it to stdout will do here.
$fetcher = 'httpget';
+# Output uppercase tags, surrounded by quotes, by default
+$lower = 0;
+$quotes = 1;
+
$out = "imgsizer-out$$";
$dir = "."; # NOTE: if you are doing <yourfile , make sure that pwd is correct!
$magick=1; # using ImageMagick by default
$/='>'; # define INPUT_RECORD_SEPARATOR to split on HTML marker boundaries
-if ("$ARGV[0]" =~ /^(--nomagick|-m)$/i) {
- $magick=0;
- shift;
+while ($i = shift @ARGV)
+{
+ last if ($i eq "--");
+
+ unless ($i =~ /^-/)
+ {
+ unshift @ARGV, $i;
+ last;
+ }
+
+ if ($i =~ /^(--nomagick|-m)$/i)
+ {
+ $magick = 0;
+ next;
+ }
+
+ if ($i =~ /^(--lower-?(case)?|-l)$/i)
+ {
+ $lower = 1;
+ next;
+ }
+
+ if ($i =~ /^(--no-?quotes?|-q)$/i)
+ {
+ $quotes = 0;
+ next;
+ }
+
+ warn "Warning: Ignoring unknown option: $i\n";
}
if (@ARGV) {
sub attrfix
# fix up a space-separated sequence of image attributes
{
- $attribs = $_[0];
+ $attribs = $_[0];
- if ($attribs !~ /SRC\s*=\s*\"([^"]*)\"/is) {
+ unless ( ($attribs =~ /SRC=([^\s]+)/is)
+ || ($attribs =~ /SRC\s*=\s*\"([^"]*)\"/is) )
+ {
&error("image \"${attribs}\"' has no SRC attribute");
return $attribs;
}
+
$url = $1;
# fetch the image
}
if ($attribs =~ /WIDTH\s*=\s*["0123456789]+/is) {
- $attribs = "$`WIDTH=\"${xc}\"$'";
+ $attribs = $` . &widthstring . $';
} else {
- $attribs .= " WIDTH=\"${xc}\"";
+ $attribs .= " " . &widthstring;
}
+
if ($attribs =~ /HEIGHT\s*=\s*["0123456789]+/is) {
- $attribs = "$`HEIGHT=\"${yc}\"$'";
+ $attribs = $` . &heightstring . $';
} else {
- $attribs .= " HEIGHT=\"${yc}\"";
+ $attribs .= " " . &heightstring;
}
+
return $attribs;
}
+
+sub widthstring
+{
+ return ($lower ? "width=" : "WIDTH=")
+ . ($quotes ? '"' : '') . $xc . ($quotes ? '"' : '');
+}
+
+sub heightstring
+{
+ return ($lower ? "height=" : "HEIGHT=")
+ . ($quotes ? '"' : '') . $yc . ($quotes ? '"' : '');
+}
.SH NAME
imgsizer \- automatically splice in height and width params for HTML IMG tags
.SH SYNOPSIS
-.B imgsizer [--nomagick] [file...]
+.B imgsizer [--nomagick] [-q] [-l] [file...]
.PP
.SH DESCRIPTION
The
argument file is not actually modified until the script completes a
successful conversion pass.
.PP
+The -q option suppresses generation of string quotes in generated
+attributes. The -l option generates attributes in lower case.
+.PP
This script is written on Perl, and thus requires a Perl interpreter
on the host system. It also requires either the
.IR identify (1)