当前位置:   article > 正文

python 照片heic格式转jpg_python heic to jpg

python heic to jpg

在jupyter里执行以下代码

import os
from PIL import Image
from pillow_heif import register_heif_opener
register_heif_opener()
  • 1
  • 2
  • 3
  • 4

单张转换-测试

image = Image.open('./test.heic')
image.save(f"{target_dir}/{file_name}.jpg", format="jpeg")
  • 1
  • 2

批量转换

指定heic目录,会在同级目录生成jpg文件目录

original_dir = r'./ImagesData/test_heic/'
target_dir = f'{original_dir}-JPG'
if not os.path.exists(target_dir):
    os.makedirs(target_dir)

for root, dirs, files in os.walk(original_dir):   
    for file in files:
        file_name = file.split('.')[0]
        original_img_path = f'{original_dir}/{file}'
        image = Image.open(original_img_path)
        image.save(f"{target_dir}/{file_name}.jpg", format="jpeg")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/一键难忘520/article/detail/924222
推荐阅读
相关标签
  

闽ICP备14008679号