Skip to content

Instantly share code, notes, and snippets.

@iqiancheng
Last active November 8, 2023 02:28
Show Gist options
  • Save iqiancheng/7e79615a93f5306da7e6750b9785c53f to your computer and use it in GitHub Desktop.
Save iqiancheng/7e79615a93f5306da7e6750b9785c53f to your computer and use it in GitHub Desktop.
HEIC 照片转png/jpg
from PIL import Image
import pyheif
import numpy as np
def decode_heic(image_filepath):
"""Decode image into numpy array, in HWC RGB format
Args:
image_filepath: str
Returns:
im_rgb: numpy.ndarray, (H, W, C), RGB, uint8
"""
i = pyheif.read_heif(open(image_filepath, 'rb'))
im_rgb = np.array(Image.frombytes(mode=i.mode, size=i.size, data=i.data))
return im_rgb
def decode_heic_to_im(image_filepath):
"""Decode image into numpy array, in HWC RGB format
Args:
image_filepath: str
Returns:
im_rgb: numpy.ndarray, (H, W, C), RGB, uint8
"""
i = pyheif.read_heif(open(image_filepath, 'rb'))
im = Image.frombytes(mode=i.mode, size=i.size, data=i.data)
return im
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment