开发笔记图格式转换heicjpg苹果相册.heic格式转成.jpg格式MG2026-04-082026-04-08 heic格式转成.jpg格式12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import osfrom PIL import Imageimport pillow_heifdef convert_heic_to_jpg(input_path): """ 将 HEIC 文件转换为 JPG """ try: heif_file = pillow_heif.read_heif(input_path) img = Image.frombytes( heif_file.mode, heif_file.size, heif_file.data, "raw" ) output_path = os.path.splitext(input_path)[0] + ".jpg" img.save(output_path, "JPEG", quality=90) print(f"✔ 转换成功: {input_path} → {output_path}") except Exception as e: print(f"✘ 转换失败: {input_path}") print("原因:", e)def convert_folder(folder): """ 批量转换指定文件夹内的所有 HEIC 文件 """ for file in os.listdir(folder): if file.lower().endswith(".heic"): full_path = os.path.join(folder, file) convert_heic_to_jpg(full_path)if __name__ == "__main__": folder = input("请输入要转换的文件夹路径(留空 = 当前目录): ").strip() if folder == "": folder = "." if not os.path.isdir(folder): print("❌ 路径不存在:", folder) else: print("开始转换 HEIC → JPG ...") convert_folder(folder) print("全部完成!")