matthewwithanm/django-imagekit

Pillow sometimes throw an error with ANTIALIASING

NorthernBlow opened this issue · 5 comments

sometimes when i made GET request to my API, pillow throw that error, but sometimes NOT. I don't know why it happening.
maybe somebody get the same problem and a resolve?

thanks a lot!

this is my code:

from imagekit import processors
from imagekit.models import ImageSpecField, ProcessedImageField
from imagekit.processors import ResizeToFit, SmartResize

class Product(models.Model):
    product_name = models.CharField(max_length=255, db_index=True)
    slug = models.SlugField(max_length=255, unique=True)
    by_brand = models.ForeignKey(Brand, on_delete=models.CASCADE, related_name='subcategories', null=True, blank=True)
    by_category = TreeForeignKey("Category", on_delete=models.SET_NULL, related_name='categories', null=True, blank=True)
    image = models.ImageField(upload_to='content/album_images/%Y%m%d/', blank=True, null=True )
    image_small = ImageSpecField(source='image', processors=[SmartResize(300, 300)],
                                 format='JPG',
                                 options={'quality': 90})
    image_medium = ImageSpecField(source='image', processors=[SmartResize(600, 600)],
                                  format='JPG',
                                  options={'quality': 97})
   

serializers.py

class ProductSerializer(serializers.ModelSerializer):
    by_category = CategorySerializer()
    image = serializers.ImageField(read_only=True)
    image_small = serializers.ImageField(read_only=True)
    image_medium = serializers.ImageField(read_only=True)


    class Meta:
        model = Product
        fields = ['by_category', 'product_name', 'slug', 'image', \
                'image_small', 'image_medium', 'price']

If this is the error:
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'
Try upgrading Pillow. ANTIALIAS is deprecated and instead they'r using LANCZOS, which is the original name of the attribute. The error it doesn't happen in your code. It happens in resize.py from pilkit package. If you can't solve try going to Resize.process where the error is and change ANTIALIAS by LANCZOS.

If this is the error: AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS' Try upgrading Pillow. ANTIALIAS is deprecated and instead they'r using LANCZOS, which is the original name of the attribute. The error it doesn't happen in your code. It happens in resize.py from pilkit package. If you can't solve try going to Resize.process where the error is and change ANTIALIAS by LANCZOS.

pip show pillow

Name: Pillow
Version: 10.0.0
Summary: Python Imaging Library (Fork)
Home-page: https://python-pillow.org
Author: Jeffrey A. Clark (Alex)
Author-email: aclark@aclark.net
License: HPND
Location: /home/northerblow/prog/rest_showcase/env/lib/python3.11/site-packages
Requires:
Required-by:

pillow already satisfied, but throw an error.

i have the same problem with Pillow when using this library.

you should change your pillow version to 9.5.0 to solve the problem

New version of pilkit (the django-imagekit dependency) where the actual processors are defined is released which is supporting Pillow 10.

Also this issue is duplicate of #566