Skip to content

Commit b3434ab

Browse files
authored
Merge pull request #2752 from terencehonles/fix-deprecation-warning
fix Pillow deprecation warning for Image.ANTIALIAS by using its new name
2 parents 970af6b + 00bcea8 commit b3434ab

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

mongoengine/fields.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747

4848
try:
4949
from PIL import Image, ImageOps
50+
51+
LANCZOS = Image.LANCZOS if hasattr(Image, "LANCZOS") else Image.ANTIALIAS
5052
except ImportError:
5153
Image = None
5254
ImageOps = None
@@ -1946,23 +1948,19 @@ def put(self, file_obj, **kwargs):
19461948
size = field.size
19471949

19481950
if size["force"]:
1949-
img = ImageOps.fit(
1950-
img, (size["width"], size["height"]), Image.ANTIALIAS
1951-
)
1951+
img = ImageOps.fit(img, (size["width"], size["height"]), LANCZOS)
19521952
else:
1953-
img.thumbnail((size["width"], size["height"]), Image.ANTIALIAS)
1953+
img.thumbnail((size["width"], size["height"]), LANCZOS)
19541954

19551955
thumbnail = None
19561956
if field.thumbnail_size:
19571957
size = field.thumbnail_size
19581958

19591959
if size["force"]:
1960-
thumbnail = ImageOps.fit(
1961-
img, (size["width"], size["height"]), Image.ANTIALIAS
1962-
)
1960+
thumbnail = ImageOps.fit(img, (size["width"], size["height"]), LANCZOS)
19631961
else:
19641962
thumbnail = img.copy()
1965-
thumbnail.thumbnail((size["width"], size["height"]), Image.ANTIALIAS)
1963+
thumbnail.thumbnail((size["width"], size["height"]), LANCZOS)
19661964

19671965
if thumbnail:
19681966
thumb_id = self._put_thumbnail(thumbnail, img_format, progressive)

0 commit comments

Comments
 (0)