Open images from a folder one by one using python?

前端 未结 2 1037
耶瑟儿~
耶瑟儿~ 2021-02-20 14:56

Hi all I need to open images from a folder one by one do some processing on images and save them back to other folder. I am doing this using following sample code.



        
2条回答
  •  一生所求
    2021-02-20 15:38

    You can use glob to read the images one by one

    import glob
    from PIL import Image
    
    
    images=glob.glob("*.jpg")
    for image in images:
        img = Image.open(image)
        img1 = img.resize(50,50)
        img1.save("newfolder\\"+image)    
    

提交回复
热议问题