7 Photos in img directory
respectively is
11.jpg 22.jpg 33.jpg 44.jpg 55.jpg 66.jpg 77.jpg
#Encoding=utf-8ImportOSImport Time fromMultiprocessing.dummyImportPool as ThreadPool fromPILImportImageSIZE= (75,75) Save_directory='Thumbs'defget_image_paths (folder):return(Os.path.join (FOLDER,F) forFinchOs.listdir (folder)if '. jpg' inchf)defcreate_thumbnail (filename): Im=image.open (filename) im.thumbnail (SIZE, Image.antialias) base, fname=os.path.split (filename) Save_path=Os.path.join (Base, Save_directory, fname) im.save (Save_path)if __name__=='__main__': Start=time.time () folder= Os.path.abspath ('img') if notos.path.exists (Os.path.join (folder,save_directory)): Os.mkdir (Os.path.join (folder,save_directory)) imag Es=get_image_paths (folder) Pool=ThreadPool () pool.map (create_thumbnail,images) pool.close () Pool.join () End=time.time ()Print(End-start)
The thumbs thumbnail file is created under the corresponding file, and then
Generate the corresponding thumbnail, the execution time is:
0.109212875366
Python multi-threaded generation thumbnail image