Skip to content

Commit

Permalink
Merge ac92836 into 995c863
Browse files Browse the repository at this point in the history
  • Loading branch information
homm committed Dec 7, 2019
2 parents 995c863 + ac92836 commit 0c15a6e
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Tests/test_file_gif.py
Expand Up @@ -754,7 +754,7 @@ def test_save_I(self):
def test_getdata(self):
# test getheader/getdata against legacy values
# Create a 'P' image with holes in the palette
im = Image._wedge().resize((16, 16))
im = Image._wedge().resize((16, 16), Image.NEAREST)
im.putpalette(ImagePalette.ImagePalette("RGB"))
im.info = {"background": 0}

Expand Down
4 changes: 3 additions & 1 deletion Tests/test_image_getdata.py
@@ -1,3 +1,5 @@
from PIL import Image

from .helper import PillowTestCase, hopper


Expand All @@ -13,7 +15,7 @@ def test_sanity(self):

def test_roundtrip(self):
def getdata(mode):
im = hopper(mode).resize((32, 30))
im = hopper(mode).resize((32, 30), Image.NEAREST)
data = im.getdata()
return data[0], len(data), len(list(data))

Expand Down
9 changes: 9 additions & 0 deletions Tests/test_image_resize.py
Expand Up @@ -150,3 +150,12 @@ def resize(mode, size):
# Test unknown resampling filter
with hopper() as im:
self.assertRaises(ValueError, im.resize, (10, 10), "unknown")

def test_default_filter(self):
for mode in "L", "RGB", "I", "F":
im = hopper(mode)
self.assertEqual(im.resize((20, 20), Image.BICUBIC), im.resize((20, 20)))

for mode in "1", "P":
im = hopper(mode)
self.assertEqual(im.resize((20, 20), Image.NEAREST), im.resize((20, 20)))
3 changes: 2 additions & 1 deletion Tests/test_imagedraw.py
Expand Up @@ -159,7 +159,8 @@ def test_bitmap(self):
# Arrange
im = Image.new("RGB", (W, H))
draw = ImageDraw.Draw(im)
with Image.open("Tests/images/pil123rgba.png").resize((50, 50)) as small:
with Image.open("Tests/images/pil123rgba.png") as small:
small = small.resize((50, 50), Image.NEAREST)

# Act
draw.bitmap((10, 10), small)
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_imagefile.py
Expand Up @@ -24,7 +24,7 @@ class TestImageFile(PillowTestCase):
def test_parser(self):
def roundtrip(format):

im = hopper("L").resize((1000, 1000))
im = hopper("L").resize((1000, 1000), Image.NEAREST)
if format in ("MSP", "XBM"):
im = im.convert("1")

Expand Down
7 changes: 7 additions & 0 deletions docs/releasenotes/7.0.0.rst
Expand Up @@ -47,6 +47,13 @@ Setting the size of TIFF images
Setting the size of a TIFF image directly (eg. ``im.size = (256, 256)``) throws
an error. Use ``Image.resize`` instead.

Default resize resampling filter
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The default resampling filter for the ``Image.resize`` method is changed to
high-quality convolution ``Image.BICUBIC`` instead of ``Image.NEAREST``.
``Image.NEAREST`` is still always used for images in "P" and "1" modes.


API Changes
===========
Expand Down
7 changes: 4 additions & 3 deletions src/PIL/Image.py
Expand Up @@ -1761,7 +1761,7 @@ def remap_palette(self, dest_map, source_palette=None):

return m_im

def resize(self, size, resample=NEAREST, box=None):
def resize(self, size, resample=BICUBIC, box=None):
"""
Returns a resized copy of this image.
Expand All @@ -1771,8 +1771,9 @@ def resize(self, size, resample=NEAREST, box=None):
one of :py:attr:`PIL.Image.NEAREST`, :py:attr:`PIL.Image.BOX`,
:py:attr:`PIL.Image.BILINEAR`, :py:attr:`PIL.Image.HAMMING`,
:py:attr:`PIL.Image.BICUBIC` or :py:attr:`PIL.Image.LANCZOS`.
If omitted, or if the image has mode "1" or "P", it is
set :py:attr:`PIL.Image.NEAREST`.
Default filter is :py:attr:`PIL.Image.BICUBIC`.
If the image has mode "1" or "P", it is
always set :py:attr:`PIL.Image.NEAREST`.
See: :ref:`concept-filters`.
:param box: An optional 4-tuple of floats giving the region
of the source image which should be scaled.
Expand Down

0 comments on commit 0c15a6e

Please sign in to comment.