import os
from PIL import Image
path = "D:\\Python\\bmp" #待处理照片的文件夹路径
for file in os.listdir(path):
if file.endswith('.bmp'):
filename = os.path.join(path, file)
new_name = path +'\\' + file[:-4] + '.jpg'
img = Image.open(filename)
img.save(new_name)
del img
os.remove(filename)
pass
def produceImage(file_in, width, height, file_out):
image = Image.open(file_in)
resized_image = image.resize((width, height), Image.ANTIALIAS)
resized_image.save(file_out)
if __name__ == '__main__':
file_in = "D:\\Python\\bmp\\in.jpg" #待处理照片的路径
width = 400
height = 300
file_out = "D:\\Python\\bmp\\out.jpg" #处理后照片的路径
produceImage(file_in, width, height, file_out)
for file in os.listdir(path):
if file.endswith('.jpg'):
filename = os.path.join(path, file)
new_name = path +'\\' + file[:-4] + '.bmp'
img = Image.open(filename)
img.save(new_name)
del img
os.remove(filename)
pass