def open(uri): format = imtools.get_format_filename(uri) local = not system.is_www_file(uri) # svg, pdf, ... if local: image = open_image_without_pil(uri, WITHOUT_PIL) if image: image.info['Format'] = image.format image.format = format return image # pil try: image = open_image_with_pil(uri) ok = True except IOError, message: ok = False
def open_image(uri): """Open local files or remote files over http. :param uri: image location :type uri: string :returns: image :rtype: pil.Image """ if system.is_www_file(uri): try: return WWW_CACHE[uri] except KeyError: f = urlopen(uri) im = WWW_CACHE[uri] = open_image_data(f.read()) return im if uri[:7] == 'file://': uri = uri[7:] return Image.open(uri)