Im trying to make a function which needs as input an image file in jpg format and outputs an array every time i call it. This is what i achieved so far:
import scipy.misc as sm
import numpy as np
from PIL import Image
def imagefunc(image):
    try:
        i = Image.open(image)
        if i.format == 'jpg':
            return i.format == 'jpg'
    except OSError:   # Checking for different possible errors in the input file
        print ('This is not a jpg image! Input has to be a jpg image!')
        return False 
    except FileNotFoundError:   # Another check for error in the input file
        print ('No image was found! Input file has to be in the same directory as this code is!')
        return False
    imgarray = np.array(sm.imread(image, True))
    return imgarray
The problem is that when i call it, "imagefunc(kvinna)" to open a jpeg picture it outputs: NameError: name 'kvinna' is not defined. What am i missing here? Is the code wrong or is it file directory problem? Thanks
 
     
    