from PIL
import Image
import os
.path
import glob
from tqdm
import tqdm
def convertjpg(jpgfile
,outdir
,width
=128,height
=128):
'''提取目录下所有图片,更改尺寸后保存到指定目录'''
img
=Image
.open(jpgfile
)
try:
new_img
=img
.resize
((width
,height
),Image
.ANTIALIAS
)
new_img
.save
(os
.path
.join
(outdir
,os
.path
.basename
(jpgfile
)))
except Exception
as e
:
print(e
)
if __name__
== '__main__':
for jpgfile
in tqdm
(glob
.glob
("D:\\Desktop\\workspace\\*.jpg")):
convertjpg
(jpgfile
,"D:\\Desktop\\workspace")
转载请注明原文地址: https://www.6miu.com/read-5038189.html