Python实现多文件批量裁剪
程序员文章站
2024-02-13 16:52:04
...
#提取目录下所有图片,更改尺寸后保存到另一目录
from PIL import Image
import os.path
import glob
def convertjpg(jpgfile,outdir,width=256,height=256):
img=Image.open(jpgfile)
try:
new_img=img.resize((width,height),Image.BILINEAR)
new_img = new_img.convert('RGB')
new_img.save(os.path.join(outdir,os.path.basename(jpgfile)))
except Exception as e:
print(e)
for jpgfile in glob.glob("D:\Flower_Clear\Old_F\Blanket flower\*.jpg"):
convertjpg(jpgfile,"D:\Flower_Clear\Cut_F\Blanket flower")