def getimagesize(url):
 try:
  from PIL import ImageFile
 except ImportError:
  try:
   import ImageFile
  except ImportError:
   return None
 try:
  import urllib2
 except ImportError:
  return None
 try:
  p = ImageFile.Parser()
  f = urllib2.urlopen(url)
  while True:
   s = f.read(1024)
   if (not s):
    break
   p.feed(s)
   if p.image:
    return ('width="%i" height="%i"' % p.image.size)
 except (IOError, ValueError):
  return None

def getimagesize ( url ) : try : from PIL import ImageFile except ImportError : try : import ImageFile except ImportError : return None try : import urllib2 except ImportError : return None try : p = ImageFile . Parser ( ) f = urllib2 . urlopen ( url ) while True : s = f . read ( 1024 ) if ( not s ) : break p . feed ( s ) if p . image : return ( 'width="%i" height="%i"' % p . image . size ) except ( IOError , ValueError ) : return None
attempts to determine an images width and height .