]> thyrsus.com Git - imgsizer.git/commitdiff
Ready to release 1.7.
authorEric S. Raymond <esr@thyrsus.com>
Sat, 19 Aug 2000 16:23:58 +0000 (16:23 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Sat, 19 Aug 2000 16:23:58 +0000 (16:23 +0000)
Makefile
imgsizer
imgsizer.xml

index ab64cb9b3c4680c2d3cd49912ccfb65756d6679a..f649571b2730d9eeb082ae0303ff319eb868d88e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 # Makefile for the imgsizer distribution
-VERS=1.6
+VERS=1.7
 
 # These choices are correct for Linux.  Season to taste.
 BINDIR = /usr/bin
index 9ffda60c022aa22251a22e57f8a36e79db0991bc..8d9e364ab06f96479db5796debf928988cbc07aa 100755 (executable)
--- a/imgsizer
+++ b/imgsizer
@@ -4,7 +4,14 @@
 # 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) {           
@@ -94,12 +131,15 @@ sub error
 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
@@ -170,14 +210,28 @@ sub attrfix
        }
 
        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 ? '"' : '');
+}
index 0d5677300e911d1a4b08bc1498f6f9a52f6689de..9623fc42dd18a7d664e2c6c37c579161743bf410 100644 (file)
@@ -3,7 +3,7 @@
 .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 
@@ -28,6 +28,9 @@ arguments, it will attempt to transform each file in place.  Each
 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)