本文记录一下把 HEIC 文件批量转换为 JPG 文件的方法,代码如下。
在使用这个脚本之前,需要在命令行中使用 brew install imagemagick
命令来安装 imagemagick
。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| import os
def heic_to_jpg(heic_path, jpg_path): command = f'magick convert {heic_path} {jpg_path}' os.system(command)
def rename_files_in_folder(folder_path, start_number): files = os.listdir(folder_path)
heic_files = [f for f in files if f.lower().endswith('.heic')]
for i, filename in enumerate(heic_files, start=start_number): old_file_path = os.path.join(folder_path, filename)
new_file_name = f'{i:03}.jpg' new_file_path = os.path.join(folder_path, new_file_name)
heic_to_jpg(old_file_path, new_file_path)
os.remove(old_file_path)
print(f'Renamed {old_file_path} to {new_file_path}')
folder_path = "YOUR_FOLDER_PATH" start_number = 0
rename_files_in_folder(folder_path, start_number)
|