Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when open a HEIC image - Failed to decode image: Invalid ftyp #19

Closed
RaphaelVRossi opened this issue Oct 27, 2022 · 4 comments
Closed

Comments

@RaphaelVRossi
Copy link
Contributor

I was testing some image format conversion on Thumbor, with pillow-avif-plugin.

And I guess I found a bug when pillow-avif try to open a HEIC file.

HEIC file tested here

# HEIC header
$ head -1 1.heic
ftypmif1mif1heic

AVIF file tested here

# AVIF header
$ head -1 image.avif
 ftypavifavifmif1miaf

Steps to reproduce

$ python3
# inside python
from PIL import Image
import pillow_avif
from io import BytesIO
import requests
body = requests.get("https://raw.githubusercontent.com/alexcorvi/heic2any/master/demo/1.heic").content
Image.open(BytesIO(body))

Log

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File ".../python3.9/site-packages/PIL/Image.py", line 3133, in open
    im = _open_core(fp, filename, prefix, formats)
  File ".../python3.9/site-packages/PIL/Image.py", line 3119, in _open_core
    im = factory(fp, filename)
  File ".../python3.9/site-packages/PIL/ImageFile.py", line 116, in __init__
    self._open()
  File ".../python3.9/site-packages/pillow_avif/AvifImagePlugin.py", line 61, in _open
    self._decoder = _avif.AvifDecoder(
ValueError: Failed to decode image: Invalid ftyp
@fdintino
Copy link
Owner

This is expected behavior. You can use pillow_heif to decode and encode HEIF files. It should be sufficient to add, where you have import pillow_avif:

import pillow_heif

pillow_heif.register_heif_opener()

@RaphaelVRossi
Copy link
Contributor Author

I already tested with pillow_heif and pillow_avif together. Or I need to use only one pillow plugin at a time?

I was looking this code here and this validation should accept header with ftypmif1mif1heic?

    coding_brands = (b"avif", b"avis")
    container_brands = (b"mif1", b"msf1")

@fdintino
Copy link
Owner

Oh I see, yes that is a bug. I'm preparing the 1.3.0 release, I'll include a fix for that.

fdintino added a commit that referenced this issue Oct 28, 2022
This will allow pillow-avif-plugin to be interoperable with the HEIC
opener in pillow_heif. Fixes #19.
@RaphaelVRossi
Copy link
Contributor Author

Thanks! @fdintino 🥳

fdintino added a commit that referenced this issue Oct 28, 2022
This will allow pillow-avif-plugin to be interoperable with the HEIC
opener in pillow_heif. Fixes #19.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants