python批量修改文件夹尺寸、jpg转png

1.python批量修改文件夹尺寸2048*1024

python批量修改文件夹尺寸、jpg转png

from PIL import Image
import os.path
import glob


def Resize(file, outdir, width, height):
    imgFile = Image.open(file)
    try:
        newImage = imgFile.resize((width, height), Image.BILINEAR)
        newImage.save(os.path.join(outdir, os.path.basename(file)))
    except Exception as e:
        print(e)


for file in glob.glob("D:/Backup/桌面/666/*.jpg"):  # 图片所在的目录
    Resize(file, "D:/Backup/桌面/777", 2048, 1024)  # 新图片存放的目录
import os
files = os.listdir("D:/Backup/桌面/777")
i=0
for file in files:
    original = "D:/Backup/桌面/777" + os.sep+ files[i]
    new = "D:/Backup/桌面/777" + os.sep + str(i+1) + ".png"
    os.rename(original,new)
    i+=1

转换大小和PNG格式之后:
python批量修改文件夹尺寸、jpg转png

上一篇:Hadoop权限问题


下一篇:慎用chmod -R 777