Skip to content

Commit

Permalink
Merge pull request #202 from alexei/fix-pil_antialias
Browse files Browse the repository at this point in the history
fix: use `Image.Resampling.LANCZOS` instead of `Image.ANTIALIAS` when available
  • Loading branch information
respondcreate authored Jan 21, 2024
2 parents f177150 + 2a7ff34 commit 0164830
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 2 additions & 2 deletions docs/writing_custom_sizers_and_filters.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ For an example, let's take a look at the ``thumbnail`` Sizer (``versatileimagefi
imagefile = BytesIO()
image.thumbnail(
(width, height),
Image.ANTIALIAS
Image.Resampling.LANCZOS
)
image.save(
imagefile,
Expand Down Expand Up @@ -311,7 +311,7 @@ is registered (see the highlighted lines in the following code block for the rel
imagefile = BytesIO()
image.thumbnail(
(width, height),
Image.ANTIALIAS
Image.Resampling.LANCZOS
)
image.save(
imagefile,
Expand Down
10 changes: 8 additions & 2 deletions versatileimagefield/versatileimagefield.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
from .registry import versatileimagefield_registry


try:
ANTIALIAS = Image.Resampling.LANCZOS
except AttributeError:
ANTIALIAS = Image.ANTIALIAS # deprecated in 9.1.0 and removed in 10.0.0


class CroppedImage(SizedImage):
"""
A SizedImage subclass that creates a 'cropped' image.
Expand Down Expand Up @@ -115,7 +121,7 @@ def crop_on_centerpoint(self, image, width, height, ppoi=(0.5, 0.5)):
# (as determined by `width`x`height`)
return cropped_image.resize(
(width, height),
Image.ANTIALIAS
ANTIALIAS
)

def process_image(self, image, image_format, save_kwargs,
Expand Down Expand Up @@ -168,7 +174,7 @@ def process_image(self, image, image_format, save_kwargs,
imagefile = BytesIO()
image.thumbnail(
(width, height),
Image.ANTIALIAS
ANTIALIAS
)
image.save(
imagefile,
Expand Down

0 comments on commit 0164830

Please sign in to comment.