]> thyrsus.com Git - imgsizer.git/commitdiff
Ready to release.
authorEric S. Raymond <esr@thyrsus.com>
Fri, 11 Jun 1999 23:35:50 +0000 (23:35 +0000)
committerEric S. Raymond <esr@thyrsus.com>
Fri, 11 Jun 1999 23:35:50 +0000 (23:35 +0000)
Makefile
imgsizer
imgsizer.xml

index d95fc187b53b90425cde043a7ad94ccb33eb35c1..2a7263e21236304f52dc28a442f4bc0493eea577 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 # Makefile for the imgsizer distribution
-VERS=1.5
+VERS=1.6
 
 # These choices are correct for Linux.  Season to taste.
 BINDIR = /usr/local/bin
@@ -9,7 +9,7 @@ install:
        cp imgsizer httpget $(BINDIR)
        cp imgsizer.man $(MANDIR)/imgsizer.1
 
-DISTDIR = imgsizer-1.5
+DISTDIR = imgsizer-1.6
 FILES = imgsizer/Makefile imgsizer/READ.ME imgsizer/httpget \
        imgsizer/imgsizer imgsizer/imgsizer.lsm \
        imgsizer/imgsizer.man
index f9857c9a71b394829567ad6d85f6ce59083c539d..9ffda60c022aa22251a22e57f8a36e79db0991bc 100755 (executable)
--- a/imgsizer
+++ b/imgsizer
@@ -4,16 +4,18 @@
 # 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
 #
 # Fix up IMG tags in given documents to contain correct sizes.
-# Requires the identify(1) program from the ImageMagick suite.
+# No longer requires the identify(1) program from the ImageMagick suite if
+# you have a decent file(1) and rdjpgcom(1).
 # To fix up sizes for non-local images it requires the httpget(1) script.
 #
 # Copy, use, and redistribute freely, but don't take my name off it and
 # clearly mark an altered version.  Fixes and enhancements cheerfully 
 # accepted.
 #
-# This is version 1.5.
+# This is version 1.6pre.
 #
 
 # Anything that can fetch a URL defined on the command line 
 $fetcher = 'httpget';  
 
 $out = "imgsizer-out$$";
-if (@ARGV) {
+$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;
+}
+
+if (@ARGV) {           
        foreach $x (@ARGV) {
                $file = $x;
                $dir = &dirname($x);
@@ -58,32 +69,19 @@ sub dirname
        return($file);
 }
 
-sub getchar
-{
-       $pushback = <STDIN> if (length($pushback) == 0);
-       $char = substr($pushback, 0, 1);
-       $pushback = substr($pushback,1);
-       return $char;
-}
-
-
 sub sizefix
 # Apply attrfix to the attributes in each image tag
 {
        while (<STDIN>) {
-               while (/<IMG\s+/i) {
-                       print $`; print $&;
-                       flush;
-                       $pushback = $';
-                       $tag = '';
-                       while (($char = &getchar) ne '>') {
-                               $tag .= $char;
-                       }
+               if (/(<IMG\s+)(.*)>/is) {
+                       print $`; print $1;
+                       $tag = $2;
                        print &attrfix($tag);
                        print ">";
-                       $_ = $pushback;
                }
-               print $_;
+               else {
+                       print $_;
+               }
        }
 }
 
@@ -98,7 +96,7 @@ sub attrfix
 {
         $attribs = $_[0];
 
-       if (!($attribs =~ /SRC="([^"]*)"/i)) {
+       if ($attribs !~ /SRC\s*=\s*\"([^"]*)\"/is) {
                &error("image \"${attribs}\"' has no SRC attribute");
                return $attribs;
        }
@@ -124,32 +122,62 @@ sub attrfix
        }
 
        # Don't try to fix up percent sizes
-       if ($attribs =~ /[0-9]%/) {
+       if ($attribs =~ /[0-9]%/s) {
                return $attribs;
        }
 
-       ($name, $size) = split(' ', `identify ${image}`);
-       unlink("imgsizer-tmp$$");
-       if ($name =~ /:/) {
-               &error("can't analyze included image ${image}");
-               return $attribs;
+       if ($magick) {
+               ($name, $size) = split(' ', `identify ${image}`);
+               unlink("imgsizer-tmp$$");
+               if ($name =~ /:/) {
+                       &error("can't analyze included image ${image}");
+                       return $attribs;
+               }
+               if (!($size=~ /([0-9]+)x([0-9]+)/)) {
+                       &error("size field ${size} is ill-formed");
+                       return $attribs;
+               }
+               $xc = $1;
+               $yc = $2;
        }
-       if (!($size=~ /([0-9]+)x([0-9]+)/)) {
-               &error("size field ${size} is ill-formed");
-               return $attribs;
+
+       else {
+               $result = `file ${image}`;
+               if ($result =~ /JPEG/) {
+                       $result = `rdjpgcom -verbose ${image}`;
+                       unlink("imgsizer-tmp$$");
+                       if ($result =~ /rdjpgcom:/) {
+                               &error("can't analyze included image ${image}");
+                               return $attribs;
+                       }
+                       else {
+                               $result =~ /(\d+)w \* (\d+)h/;
+                               $xc = $1;
+                               $yc = $2;
+                       }
+               }
+               else {
+                       unlink("imgsizer-tmp$$");
+                       if ($result !~ /(\d+) x (\d+)/) {
+                               &error("can't analyze included image ${image}");
+                               return $attribs;
+                       }
+                       else {
+                               $xc = $1;
+                               $yc = $2;
+                       }
+               }
        }
-       $xc = $1;
-       $yc = $2;
 
-       if ($attribs =~ /WIDTH=[0123456789]+/i) {
-               $attribs = "$`WIDTH=${xc}$'";
+       if ($attribs =~ /WIDTH\s*=\s*["0123456789]+/is) {
+               $attribs = "$`WIDTH=\"${xc}\"$'";
        } else {
-               $attribs .= " WIDTH=${xc}";
+               $attribs .= " WIDTH=\"${xc}\"";
        }
-       if ($attribs =~ /HEIGHT=[0123456789]+/i) {
-               $attribs = "$`HEIGHT=${yc}$'";
+       if ($attribs =~ /HEIGHT\s*=\s*["0123456789]+/is) {
+               $attribs = "$`HEIGHT=\"${yc}\"$'";
        } else {
-               $attribs .= " HEIGHT=${yc}";
+               $attribs .= " HEIGHT=\"${yc}\"";
        }
        return $attribs;
 }
index 300b29c2fe08b1b8b9539446f4b88f4bba3cf1dd..0d5677300e911d1a4b08bc1498f6f9a52f6689de 100644 (file)
@@ -3,7 +3,7 @@
 .SH NAME
 imgsizer \- automatically splice in height and width params for HTML IMG tags
 .SH SYNOPSIS
-.B imgsizer [file...]
+.B imgsizer [--nomagick] [file...]
 .PP
 .SH DESCRIPTION
 The 
@@ -29,12 +29,14 @@ argument file is not actually modified until the script completes a
 successful conversion pass.
 .PP
 This script is written on Perl, and thus requires a Perl interpreter
-on the host system.  It also requires the 
+on the host system.  It also requires either the 
 .IR identify (1)
 utility distributed in the freeware ImageMagick suite of image-display
-and manipulation tools.  The 
-.IR identify (1)
-utility is used to extract sizes from the images;
+and manipulation tools or (with --nomagick) a modern version of
+.IR file (1)
+and 
+.IR rdjpgcom (the --nomagick mode is faster).  These 
+utilities are used to extract sizes from the images;
 .B imgsizer
 itself has no knowledge of graphics formats.  The script will handle any
 image format known to 
@@ -48,14 +50,12 @@ to correctly interpret remote URLs, the freeware script
 .IR httpget (1)
 must be executable and present in your execution path;
 .B imgsizer
-will complain and fail if either
-.IR identify (1)
-or
+will complain and fail if either the required size-reporting tools or
 .IR httpget (1)
-is needed and not present.
+are needed and not present.
 .SH AUTHOR
-Eric S. Raymond <esr@thyrsus.com>.  See my home page at
-http://www.ccil.org/~esr for updates.
+Eric S. Raymond <esr@thyrsus.com>.  The --nomagick option is by Erik Rossen.
+See my home page at http://www.tuxedo.org/~esr for updates.
 .SH SEE ALSO
 .IR identify (1),
 .IR httpget (1).