Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Image.ANTIALIAS → Image.Resampling.LANCZOS (#5692)

Kaushal Sharmaf4e2a10ed6a4
diff --git a/scrapy/pipelines/images.py b/scrapy/pipelines/images.py
index 6b97190ee..67b3224b3 100644
--- a/scrapy/pipelines/images.py
+++ b/scrapy/pipelines/images.py
@@ -160,7 +160,14 @@ class ImagesPipeline(FilesPipeline):
if size:
image = image.copy()
- image.thumbnail(size, self._Image.ANTIALIAS)
+ try:
+ # Image.Resampling.LANCZOS was added in Pillow 9.1.0
+ # remove this try except block,
+ # when updating the minimum requirements for Pillow.
+ resampling_filter = self._Image.Resampling.LANCZOS
+ except AttributeError:
+ resampling_filter = self._Image.ANTIALIAS
+ image.thumbnail(size, resampling_filter)
buf = BytesIO()
image.save(buf, 'JPEG')