from PIL import Image

import os

# 指定包含图片的文件夹路径

image_folder_path = './data3_dir/leaf_rust1'

# 获取文件夹中所有文件的列表

image_files = os.listdir(image_folder_path)

# 遍历文件夹中的每个图片文件

for image_file in image_files:

    # 检查文件是否为 JFIF 格式

    if image_file.lower().endswith('.jfif'):

        # 构建完整的文件路径

        image_path = os.path.join(image_folder_path, image_file)

        # 打开图片

        with Image.open(image_path) as img:

            # 构建新的文件名,将 '.jfif' 替换为 '.jpg'

            new_image_file = image_file.lower().replace('.jfif', '.jpg')

            new_image_path = os.path.join(image_folder_path, new_image_file)

            # 保存为 JPG 格式

            img.save(new_image_path, format='JPEG')

            # 删除原始的 JFIF 格式文件(如果需要)

            os.remove(image_path)

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐