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:
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:
# Failing code sample
image = Image.open("image.png")
image.resize((100, 100), Image.ANTIALIAS) # ⚠️ Causes AttributeErrorWhy 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.
Recommended Solution: Update to LANCZOS
Permanent Fix
Replace Image.ANTIALIAS with Image.LANCZOS or the more explicit Image.Resampling.LANCZOS:
# 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
| Constant | Equivalent | Pillow Version | Recommendation |
|---|---|---|---|
Image.Resampling.LANCZOS | Full enum path | 9.0.0+ | ✅ Best future-proof option |
Image.LANCZOS | Legacy alias | 2.7.0+ | ✅ Good for most cases |
Image.ANTIALIAS | Alias for LANCZOS | Removed 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
1. Backward-Compatible Implementation (Recommended)
Use this approach if your code needs to support multiple Pillow versions:
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:
pip install Pillow==9.5.0Why 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:
# Example for easyocr users
pip install easyocr==1.7.1 # Version 1.7.1+ fixes ANTIALIAS issuesAdditional Fix Examples
Image Thumbnails
from PIL import Image
img.thumbnail((200, 200), Image.Resampling.LANCZOS) # Updated methodOpenCV Hybrid Workflows
# 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 Version | ANTIALIAS | LANCZOS | Resampling Enum | Solution |
|---|---|---|---|---|
| < 9.0.0 | Supported | Supported | ❌ | Use Image.LANCZOS |
| 9.0.0 - 9.5.0 | Deprecated | Supported | ✅ Pre-release | Use Image.Resampling.LANCZOS |
| ≥ 10.0.0 | ❌ Removed | Supported | ✅ Fully supported | Use Image.Resampling.LANCZOS |
::: note Migration Path
- Replace all
Image.ANTIALIASoccurrences - Test with Pillow ≥ 10.0.0
- Update
requirements.txtto'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.