From: Eric S. Raymond Date: Fri, 11 Jun 1999 23:35:50 +0000 (+0000) Subject: Ready to release. X-Git-Tag: 1.6 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=e2c804efaec972fed89d9e85406dd86ab335573c;p=imgsizer.git Ready to release. --- diff --git a/Makefile b/Makefile index d95fc18..2a7263e 100644 --- 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 diff --git a/imgsizer b/imgsizer index f9857c9..9ffda60 100755 --- a/imgsizer +++ b/imgsizer @@ -4,16 +4,18 @@ # imgsizer -- correct image sizes in WWW pages # # by Eric S. Raymond 30 Jul 1996 +# modified by Erik Rossen 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 @@ -21,7 +23,16 @@ $fetcher = 'httpget'; $out = "imgsizer-out$$"; -if (@ARGV) { +$dir = "."; # NOTE: if you are doing '; # 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 = 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 () { - while (/') { - $tag .= $char; - } + if (/(/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; } diff --git a/imgsizer.xml b/imgsizer.xml index 300b29c..0d56773 100644 --- a/imgsizer.xml +++ b/imgsizer.xml @@ -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 . See my home page at -http://www.ccil.org/~esr for updates. +Eric S. Raymond . 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).