AVIF for Django-imagekit?
Let’s say this is my code, powered by django-imagekit.
from django.db import models
from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFill
class Profile(models.Model):
avatar = models.ImageField(upload_to='avatars')
avatar_thumbnail = ImageSpecField(source='avatar',
processors=[ResizeToFill(100, 50)],
format='JPEG',
options={'quality': 60})
How can this be modified to support AVIF as the target image format? I know JPEG and even WebM is supported. But I don’t think AVIF is. So is there any way this can be modified to accomplish it?
I figured it out. I simply had to install pillow-avif-plugin
and
import pillow_avif
at the top of my models.py. Then it just magically works when my code is set to
from django.db import models
from imagekit.models import ImageSpecField
from imagekit.processors import ResizeToFill
import pillow_avif
class Profile(models.Model):
avatar = models.ImageField(upload_to='avatars')
avatar_thumbnail = ImageSpecField(source='avatar',
processors=[ResizeToFill(100, 50)],
format='AVIF',
options={'quality': 60})