Closed paolobenve closed 2 years ago
This plugin does load AVIF images, and there are quite a few decoder tests that verifies the functionality. The mime gets registered with pillow here, so it shouldn't matter if it's missing from your system's mime database.
There are a few possible reasons why this plugin might not be loading images as you would expect:
import pillow_avif
somewhere in your application before PIL.Image.open
. If that import is missing, or if it occurs after you've tried to open a file, it won't have registered itself with pillow.from pillow_avif import _avif
print(_avif.AvifCodecVersions())
If you are using the mac or manylinux wheels from pypi, this should output:
dav1d [dec]:0.9.2, aom [enc/dec]:3.1.3, rav1e [enc]:0.4.0 (0.4.0), svt [enc]:0.8.7
If you get an error trying to run the above lines that would be indicative of an issue either with the libavif installed on your machine or with how the C extension is compiled.
accept
function to tell Pillow whether it should use your plugin to open a file. If bytes 4-12 of your file are ftypavif
or ftypavif
, then it is definitely an AVIF image. If instead you have ftypmif1
or ftypmsf1
, pillow-avif-plugin would still attempt to open it, but there's a chance that the image is actually HEIF. And if it is, the extension won't throw an error to allow for future pillow HEIF support or for interoperability with a pillow HEIF plugin.@fdintino Thank you for you answer!
you'll need to have import pillow_avif
I had commented it out, sorry
The images are now recognized, however, I'm getting the mime type with
import magic
self.mime_type = magic.detect_from_filename(media_path).mime_type
but since my libmagic
doesn't know avif, I get the wrong value.
Have I a way to get the mime type correctly from PIL?
I think you should be able to get them with im.get_format_mimetype()
thank you!
I'm not certain, but I'd say that the plugin claims to have the ability to load avif images.
Actually I could save images to avif, but I couldn't load them. With some image pillow reports mime type
image/heif
, with othersapplication/octet-stream
.Actually my mime database doesn't know
image/avif
, and I wonder if the reason why pillow doesn't load avif images is that it needs to know its mime type.