Python multi-threaded generation thumbnail image

Source: Internet
Author: User

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): (filename) im.thumbnail (SIZE, Image.antialias) base, fname=os.path.split (filename) Save_path=Os.path.join (Base, Save_directory, fname) (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 () (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:


Python multi-threaded generation thumbnail image

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.