From 6f44ae1d27fa89a9e313e0da9dbfe3d129bb0763 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 30 Sep 2018 15:08:35 +1000 Subject: [PATCH] Only deprecate setting of TIFF image sizes --- Tests/test_file_tiff.py | 8 ++++++++ src/PIL/TiffImagePlugin.py | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index a920032f3..a92c2351f 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -69,6 +69,14 @@ class TestFileTiff(PillowTestCase): self.assertEqual(str(e.exception), "Not allowing setting of legacy api") + def test_size(self): + filename = "Tests/images/pil168.tif" + im = Image.open(filename) + + def set_size(): + im.size = (256, 256) + self.assert_warning(DeprecationWarning, set_size) + def test_xyres_tiff(self): filename = "Tests/images/pil168.tif" im = Image.open(filename) diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index 8bd3bef10..d18ca39d8 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -1049,6 +1049,19 @@ class TiffImageFile(ImageFile.ImageFile): "Return the current frame number" return self.__frame + @property + def size(self): + return self._size + + @size.setter + def size(self, value): + warnings.warn( + 'Setting the size of a TIFF image direcly is deprecated, and will ' + 'be removed in a future version. Use the resize method instead.', + DeprecationWarning + ) + self._size = value + def load(self): if self.use_load_libtiff: return self._load_libtiff()