# Verify and merge Lucien Saviot's patch to produce XHTML from XHTML input.
# Also his change to handle spurious lin e breaks produced by Dave Raggett's
# tidy(1) utility.
+#
+# Modified by Andrew Gwozdziewycz <gwozdzie@lucas.cis.temple.edu>, 17 June 2004
+#
+# Added support for the Python Imaging Library to determine size in case of
+# failure from file(1), rdjpgcom(1) and identify(1).
import sys, os, getopt, string, re, urllib, commands
except ImportError:
import cmp
-version = "2.5, 14 November 2003";
+version = "2.7, 05 Aug 2004";
splash = """imgsizer version %s, Eric S. Raymond <esr@thyrsus.com>
-See <http://www.tuxedo.org/~esr/software.html> for updates."""
+See <http://www.catb.org/~esr/software.html> for updates."""
usage = """Usage: imgsizer [OPTIONS] [HTML File]
def imgsize(src):
"Return the image size in pixels for a given image source."
- global magick, rdjpgcom
+ global magick, rdjpgcom, pythonimage
try:
(filename, headers) = urllib.urlretrieve(src)
except IOError:
elif status == 127:
sys.stderr.write("imgsizer: giving up on ImageMagick\n")
magick = 0
+ # if that fails, try at _LAST_ resort Python Imaging Library
+ # open doesn't actually load all the data, so it shouldn't be too expensive
+ if pythonimage:
+ try:
+ import Image
+ pyimg = Image.open(filename)
+ return pyimg.size
+ except (ImportError, IOError):
+ sys.stderr.write("imgsizer: giving up on Python Imaging Library\n")
+ pythonimage = 0
+ pass
+
# All attempts failed
sys.stderr.write("imgsizer: couldn't analyze %s\n" % src)
# Optimization latches -- if an attempt to invoke a command returns 127
# "not found" there will turn off and that command won't be tried again.
-magick = 1 # using ImageMagick by default
-rdjpgcom = 1 # using rdjpcom by default
+magick = 0 # using ImageMagick by default
+rdjpgcom = 0 # using rdjpcom by default
+pythonimage = 1 # use python imaging library
# Collect options from the environment first, then the command line
options = os.environ.get("IMGSIZER")