- pip install whatimage
- pip install pyheif
import whatimage
import pyheif
from PIL import Image
import glob
def heic_to_jpg(heic_img_path):
with open(heic_img_path, 'rb') as f:
heic_img = f.read()
img_format = whatimage.identify_image(heic_img)
# print('img_format = ', img_format)
if img_format in ['heic']:
img = pyheif.read_heif(heic_img)
# print('img = ', img)
# print('img.metadata = ', img.metadata)
pi = Image.frombytes(mode=img.mode, size=img.size, data=img.data)
# print('pi = ', pi)
pi.save(heic_img_path[:-5]+".jpg", format="jpeg",)
def main():
file_paths = glob.glob("./*/iphone/*.HEIC")
for file_path in file_paths:
print('file_path = ', file_path)
heic_to_jpg(file_path)
if __name__ == "__main__":
files = ''
files_android = glob.glob('./*/android/*.*g')
files_iphone = glob.glob('./*/iphone/*.*g')
print(len(files_android))
print(len(files_iphone))
'''
原文链接:https://blog.csdn.net/Strive_For_Future/article/details/119332645
'''