系统中遇到有苹果手机上传.heic格式图片,传输到前端无法打开,需要进行转换成jpg或其他常用格式,使用python来进行处理
import whatimage
import pyheif
from PIL import Image
from pillow_heif import register_heif_opener
register_heif_opener()
heic_img_path = "h.heic"
with open(heic_img_path, 'rb') as f:
heic_img = f.read()
img_format = whatimage.identify_image(heic_img)
if img_format in ['heic']:
pi = Image.open(heic_img_path)
pi.save("heic.jpg")
win系统下pyheif模块需要python2.7才支持!
© 版权声明
THE END
暂无评论内容