Skip to content

Commit

Permalink
Fix to use the new import style for PIL, also make it optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
keith.dart committed Jun 17, 2013
1 parent 527c2c0 commit 136211b
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions WWW/pycopia/WWW/XHTML.py
Expand Up @@ -41,7 +41,10 @@

import itertools

import Image # from PIL, for automated image size
try:
from PIL import Image
except ImportError:
Image = None

from pycopia.urlparse import quote_plus
from pycopia.textutils import identifier
Expand Down Expand Up @@ -235,19 +238,20 @@ def get_new_element(self, name, **kwargs):

def new_image(self, _imagefile, _alt=None, **kwargs):
check_flag(kwargs, "ismap")
try:
im = Image.open(_imagefile)
except IOError:
pass
else:
x, y = im.size
kwargs["width"] = str(x)
kwargs["height"] = str(y)
if Image is not None:
try:
im.close()
except:
im = Image.open(_imagefile)
except IOError:
pass
del im
else:
x, y = im.size
kwargs["width"] = str(x)
kwargs["height"] = str(y)
try:
im.close()
except:
pass
del im
kwargs["src"] = _imagefile # XXX adjust for server alias?
if _alt:
kwargs["alt"] = _alt
Expand Down

0 comments on commit 136211b

Please sign in to comment.