# constants from PIL import Image # needed for web support import urllib.request, io # process image acquistion and display ''' Function get_web_image() return image at web resource indicated by link ''' def get_web_image( link ) : # get access to module Image from PIL import Image ''' Returns a pil image of the image named by link ''' # get a connection to the web resource name by link stream = urllib.request.urlopen( link ) # get the conents of the web resource data = stream.read() # convert the data to bytes bytes = io.BytesIO( data ) # get the image represented by the bytes image = Image.open( bytes ) # convert the image to RGB format image = image.convert('RGB') # hand back the image return image ''' Function get_selfie() returns a selfie of the indicated id ''' def get_selfie( id ) : REPOSITORY = 'http://www.cs.virginia.edu/~cs1112/people/' link = REPOSITORY + id + '/selfie.jpg' return get_web_image( link ) ''' Function get_image() returns a image from online or local source or an existing Image ''' def get_image( source ) : try : if ( str( type( source ) ) == "" ) : # check to if source is an existing Image image = source elif ( 'http://' == source[ 0 : 7 ].lower() ) : # look at the initial characters of source to see if its on the web # initial characters indicate the image is out on the web image = get_web_image( source ) else : # initial characters indicate the image is a local file image = Image.open( source ) except : image = None return image.copy()