''' Purpose: provide overlay of pillow support ''' from PIL import Image def get_selfie( person ) : ''' Returns a new copy of the cs 1112 of selfied uploaded by person ''' PEOPLE_FOLDER = "http://www.cs.virginia.edu/~cs1112/people/" link = PEOPLE_FOLDER + person + "/selfie.jpg" img = get_image( link ) return img def get_image( link ) : ''' Returns a new copy of the image at link ''' import urllib.request, io from PIL import Image stream = urllib.request.urlopen( link ) data = stream.read() pixels = io.BytesIO( data ) img = Image.open( pixels ) img = img.convert('RGB') #load_canvas( img ) return img def resize( img, max_w, max_h ) : ''' Scales img to ensure that it fits within a max_w x max_h box ''' w, h = img.size scale_w = w / max_w scale_h = h / max_h scale = max( scale_w, scale_h ) if ( scale > 1 ) : w = int( w / scale ) h = int( h / scale ) img = img.resize( ( w, h ) ).convert( 'RGB' ) return img