Python批量改变图片像素
笔者实验环境:
Python 3.6
PIL 7.0.0
图片为png格式
from PIL import Image
import os.path
import glob
def convertpng(pngfile,outdir,width=你要的宽度,height=你要的宽度):
img = Image.open(pngfile)
try:
new_img = img.resize((width,height),Image.BILINEAR)
new_img.save(os.path.join(outdir,os.path.basename(pngfile)))
except Exception as e:
print(e)
for pngfile in glob.glob("\\*.png"):
convertpng(pngfile,"")
内容未完待续,后续内容请关注CSDN本专栏
更多内容请关注公众号