Skip to content

PIL Image "ANTIALIAS" AttributeError Fix

Problem: Missing ANTIALIAS Attribute in Pillow

When trying to resize images using Python Imaging Library (Pillow), you may encounter this error:

python
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

This commonly occurs in code that uses image resizing with ANTIALIAS, especially in older scripts or tutorials. The core issue is Pillow 10.0.0's removal of the ANTIALIAS constant after it was deprecated in earlier versions.

Typical scenario:

python
# Failing code sample
image = Image.open("image.png")
image.resize((100, 100), Image.ANTIALIAS)  # ⚠️ Causes AttributeError

Why ANTIALIAS Disappeared

Pillow developers removed ANTIALIAS in v10.0.0 to standardize terminology with other imaging libraries. The Lanczos resampling algorithm (what ANTIALIAS used internally) has been industry-standard since 1979.

Permanent Fix

Replace Image.ANTIALIAS with Image.LANCZOS or the more explicit Image.Resampling.LANCZOS:

python
# Corrected image resizing
from PIL import Image, ImageTk
import tkinter as tk

image = Image.open("VC.png")
# Updated resizing method
resized = image.resize((20, 20), Image.LANCZOS)  # ✅ Use LANCZOS

# Complete Tkinter integration
tk_image = ImageTk.PhotoImage(resized)
window = tk.Tk()
tk.Label(window, image=tk_image).pack()
window.mainloop()

Explanation of Filter Options

ConstantEquivalentPillow VersionRecommendation
Image.Resampling.LANCZOSFull enum path9.0.0+✅ Best future-proof option
Image.LANCZOSLegacy alias2.7.0+✅ Good for most cases
Image.ANTIALIASAlias for LANCZOSRemoved in 10.0.0⚠️ Do not use

Why LANCZOS?

Both ANTIALIAS and LANCZOS refer to the exact same Lanczos resampling algorithm. The only change is the constant name. Updating references to LANCZOS provides identical results without errors.

Version Management Methods

Use this approach if your code needs to support multiple Pillow versions:

python
from PIL import Image

# Version check for compatibility
if hasattr(Image, 'Resampling'):
    resampling = Image.Resampling.LANCZOS
else:
    resampling = Image.LANCZOS  # Fallback for older Pillow versions

# Unified usage
image.resize((100, 100), resampling)

2. Downgrading Pillow (Temporary Workaround)

While not recommended for new projects, downgrading may help legacy systems. Install Pillow 9.5:

bash
pip install Pillow==9.5.0

Why Downgrading is Risky

  • ❌ Loses security updates and bug fixes
  • ❌ Creates dependency conflicts
  • ❌ Postpones inevitable code updates
    Use only as a temporary measure while updating your codebase.

3. Handling Third-Party Libraries

If encountering errors in libraries like easyocr:

bash
# Example for easyocr users
pip install easyocr==1.7.1  # Version 1.7.1+ fixes ANTIALIAS issues

Additional Fix Examples

Image Thumbnails

python
from PIL import Image

img.thumbnail((200, 200), Image.Resampling.LANCZOS)  # Updated method

OpenCV Hybrid Workflows

python
# Corrected OpenCV + Pillow integration
import cv2
from PIL import Image

img = cv2.imread("image.jpg")
pil_img = Image.fromarray(img)
resized = pil_img.resize((300, 300), Image.LANCZOS)
cv_img = cv2.cvtColor(np.array(resized), cv2.COLOR_RGB2BGR)

Version Support Reference

Pillow VersionANTIALIASLANCZOSResampling EnumSolution
< 9.0.0SupportedSupportedUse Image.LANCZOS
9.0.0 - 9.5.0DeprecatedSupported✅ Pre-releaseUse Image.Resampling.LANCZOS
≥ 10.0.0❌ RemovedSupported✅ Fully supportedUse Image.Resampling.LANCZOS

::: note Migration Path

  1. Replace all Image.ANTIALIAS occurrences
  2. Test with Pillow ≥ 10.0.0
  3. Update requirements.txt to 'Pillow>=10.0'
    :::

Best practice is migrating to Image.Resampling.LANCZOS where possible. This provides maximum forward compatibility and makes your code resilient to future Pillow updates.