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.
Sounds like you want multithreading. Here's a quick rev that'll do that.
from multiprocessing import Pool
import os
path1 = "some/path"
path2 = "some/other/path"
listing = os.listdir(path1)
p = Pool(5) # process 5 images simultaneously
def process_fpath(path):
im = Image.open(path1 + path)
im.resize((50,50)) # need to do some more processing here
im.save(os.path.join(path2,path), "JPEG")
p.map(process_fpath, listing)
(edit: use multiprocessing instead of Thread
, see that doc for more examples and information)