通过源图片(11.jpg)生成指定张数和指定大小(140*120像素)的图片
1 # -*- coding: utf-8 -*- 2 import threading 3 4 from PIL import Image 5 6 image_size = range(1, 10) 7 8 def start(): 9 print('主线程。。', threading.current_thread()) 10 for size in image_size: 11 t = threading.Thread(target=create_image, args=(size,)) 12 t.start() 13 14 def create_image(size): 15 print('子线程。。', threading.current_thread()) 16 pri_image = Image.open(r"C:UsersMezhouPycharmProjectsuntitled ryagain11.jpg") 17 pri_image.resize((140,120), Image.ANTIALIAS).save(r"C:/Users/Mezhou/PycharmProjects/untitled/tryagain/img/pic_%d.jpg" %size) 18 print('pic_%d.jpg已生成!' %size) 19 20 if __name__ == "__main__": 21 start() 22 while threading.active_count()!=1:#判断当前活动的线程是几个,如果是1的话,说明子线程已经执行完成了 23 pass 24 print('图片已全部生成!')
参考网址:https://www.jb51.net/article/91492.htm