Removed ICNS (width, height, scale) sizes

This commit is contained in:
Andrew Murray 2025-07-01 21:15:08 +10:00
parent 9fbc255ce5
commit aaf217cea0
3 changed files with 20 additions and 40 deletions

View File

@ -93,21 +93,11 @@ def test_sizes() -> None:
with Image.open(TEST_FILE) as im: with Image.open(TEST_FILE) as im:
assert isinstance(im, IcnsImagePlugin.IcnsImageFile) assert isinstance(im, IcnsImagePlugin.IcnsImageFile)
for w, h, r in im.info["sizes"]: for w, h, r in im.info["sizes"]:
wr = w * r
hr = h * r
with pytest.warns(
DeprecationWarning, match=r"Setting size to \(width, height, scale\)"
):
im.size = (w, h, r)
im.load()
assert im.mode == "RGBA"
assert im.size == (wr, hr)
# Test using load() with scale # Test using load() with scale
im.size = (w, h) im.size = (w, h)
im.load(scale=r) im.load(scale=r)
assert im.mode == "RGBA" assert im.mode == "RGBA"
assert im.size == (wr, hr) assert im.size == (w * r, h * r)
# Check that we cannot load an incorrect size # Check that we cannot load an incorrect size
with pytest.raises(ValueError): with pytest.raises(ValueError):

View File

@ -32,14 +32,6 @@ vulnerability introduced in FreeType 2.6 (:cve:`2020-15999`).
.. _2.10.4: https://sourceforge.net/projects/freetype/files/freetype2/2.10.4/ .. _2.10.4: https://sourceforge.net/projects/freetype/files/freetype2/2.10.4/
ICNS (width, height, scale) sizes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. deprecated:: 11.0.0
Setting an ICNS image size to ``(width, height, scale)`` before loading has been
deprecated. Instead, ``load(scale)`` can be used.
ExifTags.IFD.Makernote ExifTags.IFD.Makernote
^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^
@ -189,6 +181,14 @@ ImageDraw.getdraw hints parameter
The ``hints`` parameter in :py:meth:`~PIL.ImageDraw.getdraw()` has been removed. The ``hints`` parameter in :py:meth:`~PIL.ImageDraw.getdraw()` has been removed.
ICNS (width, height, scale) sizes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. deprecated:: 11.0.0
Setting an ICNS image size to ``(width, height, scale)`` before loading has been
removed. Instead, ``load(scale)`` can be used.
Image isImageType() Image isImageType()
^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^

View File

@ -25,7 +25,6 @@ import sys
from typing import IO from typing import IO
from . import Image, ImageFile, PngImagePlugin, features from . import Image, ImageFile, PngImagePlugin, features
from ._deprecate import deprecate
enable_jpeg2k = features.check_codec("jpg_2000") enable_jpeg2k = features.check_codec("jpg_2000")
if enable_jpeg2k: if enable_jpeg2k:
@ -275,18 +274,12 @@ class IcnsImageFile(ImageFile.ImageFile):
self.best_size[1] * self.best_size[2], self.best_size[1] * self.best_size[2],
) )
@property # type: ignore[override] @property
def size(self) -> tuple[int, int] | tuple[int, int, int]: def size(self) -> tuple[int, int]:
return self._size return self._size
@size.setter @size.setter
def size(self, value: tuple[int, int] | tuple[int, int, int]) -> None: def size(self, value: tuple[int, int]) -> None:
if len(value) == 3:
deprecate("Setting size to (width, height, scale)", 12, "load(scale)")
if value in self.info["sizes"]:
self._size = value # type: ignore[assignment]
return
else:
# Check that a matching size exists, # Check that a matching size exists,
# or that there is a scale that would create a size that matches # or that there is a scale that would create a size that matches
for size in self.info["sizes"]: for size in self.info["sizes"]:
@ -299,10 +292,7 @@ class IcnsImageFile(ImageFile.ImageFile):
raise ValueError(msg) raise ValueError(msg)
def load(self, scale: int | None = None) -> Image.core.PixelAccess | None: def load(self, scale: int | None = None) -> Image.core.PixelAccess | None:
if scale is not None or len(self.size) == 3: if scale is not None:
if scale is None and len(self.size) == 3:
scale = self.size[2]
assert scale is not None
width, height = self.size[:2] width, height = self.size[:2]
self.size = width * scale, height * scale self.size = width * scale, height * scale
self.best_size = width, height, scale self.best_size = width, height, scale