一、.引入两个库 " import os " 、 " from PIL import Image "
import os
from PIL import Image
二、 第二步,直接上代码
import os
from PIL import Image
def batch_convert_webp_to_jpg(input_folder, output_folder):
if not os.path.exists(output_folder):
os.makedirs(output_folder)
for filename in os.listdir(input_folder):
if filename.endswith(".webp"):
input_path = os.path.join(input_folder, filename)
output_path = os.path.join(output_folder, os.path.splitext(filename)[0] + ".jpg")
try:
image = Image.open(input_path)
if image.mode != "RGB":
image = image.convert("RGB")
image.save(output_path, "JPEG")
print(f"成功将 {input_path} 转换为 {ou