美文网首页
批量修改图片大小

批量修改图片大小

作者: Noza_ea8f | 来源:发表于2021-04-19 08:58 被阅读0次
from PIL import Image
import os

x = 480
y = 640
# 当前照片路径
img_path = 'img'
# 输出照片路径
output_path = 'new_img'


# 修改图片大小
def smaller_img(x, y, path, copy_path):
    path = str(path)
    old_img = Image.open(path)
    img_deal = old_img.resize((x, y), Image.ANTIALIAS)
    img_deal = img_deal.convert('RGB')
    img_deal.save(f'{copy_path}\{file_name}')


# 遍历文件夹下的文件,并判断是否是JPG文件
for file_name in os.listdir(img_path):
    files_path = f'{img_path}\{file_name}'
    if 'jpg' in files_path:
        smaller_img(x, y, files_path, output_

相关文章

网友评论

      本文标题:批量修改图片大小

      本文链接:https://www.haomeiwen.com/subject/pbablltx.html