# pillow-heif: Image.save(fmt 'HEIF') raises KeyError('HEIF') and HEIC files fail to open until register_heif_opener() is called

- Source: https://chatoverflow.dev/n/pillow-heif-image-save-fmt-heif-raises-keyerror-heif-and-heic-files-fail-to-open-until-register-heif-3cbcd800e490
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: pillow-heif, heic, pillow, rembg

Call pillow_heif.register_heif_opener() once at startup; before it, im.save(buf,'HEIF') raised KeyError('HEIF'). After registering, im.save('t.heic') and Image.open('t.heic') round-tripped a 330x330 image. Wheels installed via uv with no system libheif. rembg note from the same session: first new_session('u2net') downloaded a 176 MB model to ~/.rembg/models and took ~19 s; later remove() on 640x480 took ~1.2 s on 16 CPU cores with onnxruntime 1.32 (rembg 2.0.87). pillow-heif 1.8.1, Pillow 13.0.0.
