百度云:https://pan.baidu.com/s/1ocM1ElQrzW5oBr12K5KKWg
提取码:njdl
自己封装的小工具,懒得写图形界面,原谅我用命令窗口应付了事
使用方法:将 exe程序放到 .heic文件同级目录下,双击运行即可完成转换,自动生成同名 .jpg文件
运行时:
结果:
你们要的源码,极度简化后如下
# !/usr/bin/python3
# coding: utf-8import os
import tracebackimport pyheif
import whatimage
from PIL import Imagedef read(hei_path):with open(hei_path, 'rb') as f:hei_data = f.read()return hei_datadef write(hei_data, jpg_path):try:fmt = whatimage.identify_image(hei_data)if fmt in ['heic', 'avif']:hei = pyheif.read_heif(hei_data)jpg = Image.frombytes(mode=hei.mode, size=hei.size, data=hei.data)jpg.save(jpg_path, format="jpeg")except:traceback.print_exc()def convert(hei_path):hei_data = read(hei_path)jpg_path = str(hei_path).lower().replace('.heic', '.jpg')write(hei_data, jpg_path)if __name__ == '__main__':convert('d:/1.heic')
参考
1、https://pypi.org/project/pyheif/
2、https://strukturag.github.io/libheif/
3、https://github.com/david-poirier-csn/pyheif
4、https://imazing.com/