1. pip install whatimage
    2. pip install pyheif
    1. import whatimage
    2. import pyheif
    3. from PIL import Image
    4. import glob
    5. def heic_to_jpg(heic_img_path):
    6. with open(heic_img_path, 'rb') as f:
    7. heic_img = f.read()
    8. img_format = whatimage.identify_image(heic_img)
    9. # print('img_format = ', img_format)
    10. if img_format in ['heic']:
    11. img = pyheif.read_heif(heic_img)
    12. # print('img = ', img)
    13. # print('img.metadata = ', img.metadata)
    14. pi = Image.frombytes(mode=img.mode, size=img.size, data=img.data)
    15. # print('pi = ', pi)
    16. pi.save(heic_img_path[:-5]+".jpg", format="jpeg",)
    17. def main():
    18. file_paths = glob.glob("./*/iphone/*.HEIC")
    19. for file_path in file_paths:
    20. print('file_path = ', file_path)
    21. heic_to_jpg(file_path)
    22. if __name__ == "__main__":
    23. files = ''
    24. files_android = glob.glob('./*/android/*.*g')
    25. files_iphone = glob.glob('./*/iphone/*.*g')
    26. print(len(files_android))
    27. print(len(files_iphone))
    28. '''
    29. 原文链接:https://blog.csdn.net/Strive_For_Future/article/details/119332645
    30. '''