Home > OS >  How to convert JPG images to AVIF with Python
How to convert JPG images to AVIF with Python

Time:10-14

Python's Pillow doesn't seems to support AVIF files yet, and other packages like pyheif, only support reading. Is there any Python tool to convert jpg images to the new avif format?

CodePudding user response:

As far as I know, there is no support for 'avif' right now. But there are API supports. For example, this API is doing well. Maybe security issues could occur. The website doesn't look good, but functionally doing well.

I've checked up API source code a little, and I found out that you could make this conversion without needing this API. API is using magick command to make this conversion. I don't know how to use this command, but I think you could figure it out if you search a little, or check out the source code.

CodePudding user response:

You can to do this with pillow and pillow-avif-plugin:

from PIL import Image
import pillow_avif

JPGimg = Image.open(<filename>   'jpg')
JPGimg.save(<filename>   '.AVIF','AVIF')

You need to install pillow AVIF to do that.

  • Related