def getImage()

in api/ImageSimilarity/deployment/app.py [0:0]


def getImage(img_input, input_type):
    '''
    This method will load images into the correct format based on the input_type to the API. This will handle the following input_types

    input_type:
     0: url to the image
     1: file was sent 
     2: base 64 byte stream was sent
    '''
    global img_width
    global img_height
    
    if input_type == 0:
            with urlopen(img_input) as file:
                img = Image.open(file)
    elif input_type == 1:
            log('loading image from file uploaded')
            img = Image.open(io.BytesIO(img_input)).resize((img_width,img_height))
    elif input_type == 2:
            img = Image.open(io.BytesIO(base64.b64decode(img_input)))   

    if img.mode != 'RGB':
        img = img.convert('RGB')
        
    return img