赞
踩
参考链接:
https://stackoverflow.com/questions/54395735/how-to-work-with-heic-image-file-types-in-python
https://github.com/david-poirier-csn/pyheif
https://pypi.org/project/pyheif/
直接上代码
heic_to_jpg.py
- import subprocess
- import os
- import io
- import whatimage
- import pyheif
- import traceback
- from PIL import Image
-
-
- def decodeImage(bytesIo):
- try:
- fmt = whatimage.identify_image(bytesIo)
- # print('fmt = ', fmt)
- if fmt in ['heic']:
- i = pyheif.read_heif(bytesIo)
- # print('i = ', i)
- # print('i.metadata = ', i.metadata)
- pi = Image.frombytes(mode=i.mode, size=i.size, data=i.data)
- # print('pi = ', pi)
- pi.save('heeh.jpg', format="jpeg")
- except:
- traceback.print_exc()
-
-
- def read_image_file_rb(file_path):
- with open(file_path, 'rb') as f:
- file_data = f.read()
- return file_data
-
-
- if __name__ == "__main__":
- file_path = './test_image.HEIC'
- print('file_path = ', file_path)
-
- data = read_image_file_rb(file_path)
- # print('data = ', data)
- decodeImage(data)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。