How to work with HEIC image file types in Python

后端 未结 6 1089
醉梦人生
醉梦人生 2021-01-31 18:08

The High Efficiency Image File (HEIF) format is the default when airdropping an image from an iPhone to a OSX device. I want to edit and modify these .HEIC files with Python.

6条回答
  •  轮回少年
    2021-01-31 18:22

    This will do go get the exif data from the heic file

    import pyheif
    import exifread
    import io
    
    heif_file = pyheif.read_heif("file.heic")
    
    for metadata in heif_file.metadata:
    
        if metadata['type'] == 'Exif':
            fstream = io.BytesIO(metadata['data'][6:])
    
        exifdata = exifread.process_file(fstream,details=False)
    
        # example to get device model from heic file
        model = str(exifdata.get("Image Model"))
        print(model)
    

提交回复
热议问题