How to create set of image files in folder using python and PIL
Question: I am resizing a set of images and storing resized image to new folder.my
sample code is

    
    
    import cv2
    import PIL
    import Image
    import os
    
    def resize_all(path1,path2):
     resolution = (200,200)
     scaler = Image.ANTIALIAS
     if not os.path.exists(path2):
        os.makedirs(path2)
     listing=os.listdir(path1)
     for file in listing:
        img=Image.open(path1 + file)
        res=img.resize(resolution , Image.ANTIALIAS)
        cv2.imwrite(os.path.join(path2, res),'image')
    
    def main():
     resize_all('d:\\Emmanu\\project-data\\birds\\','d:\\Emmanu\\project-data\\new\\')
    
    if __name__ == '__main__':main()
    

But when i execute i am getting error as Full Traceback added **EDIT**

    
    
    Traceback (most recent call last):
    File "D:/Emmanu/ImageClassification/preprocessing.py", line 20, in <module>
    if __name__ == '__main__':main()
    File "D:/Emmanu/ImageClassification/preprocessing.py", line 18, in main
    resize_all('d:\\Emmanu\\project-data\\birds\\','d:\\Emmanu\\project-data\\new\\')
    File "D:/Emmanu/ImageClassification/preprocessing.py", line 15, in resize_all
    cv2.imwrite(os.path.join(path2, res),'image')
    File "C:\Python27\lib\ntpath.py", line 67, in join
    p_drive, p_path = splitdrive(p)
    File "C:\Python27\lib\ntpath.py", line 115, in splitdrive
    if len(p) > 1:
    File "C:\Python27\lib\site-packages\PIL\Image.py", line 512, in __getattr__
    raise AttributeError(name)
    AttributeError: __len__
    


Answer: Finally got answer, Modified the for loop

    
    
    for i,file in enumerate(listing):
        img=Image.open(path1 + file)
        res=img.resize(resolution , Image.ANTIALIAS)
        res.save(path2+'h{}.jpg'.format(i))
    

Now all my images are resized and saved to a new folder

