Skip to content

Commit 8f92da6

Browse files
akxradarherehugovk
authored
Deprecate JpegImageFile.load_djpeg (#9924)
Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
1 parent 23cbae1 commit 8f92da6

5 files changed

Lines changed: 29 additions & 5 deletions

File tree

Tests/test_file_jpeg.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,8 @@ def test_restart_markers(self, blocks: int, rows: int, markers: int) -> None:
734734
def test_load_djpeg(self) -> None:
735735
with Image.open(TEST_FILE) as img:
736736
assert isinstance(img, JpegImagePlugin.JpegImageFile)
737-
img.load_djpeg()
737+
with pytest.warns(DeprecationWarning, match="load_djpeg"):
738+
img.load_djpeg()
738739
assert_image_similar_tofile(img, TEST_FILE, 5)
739740

740741
def test_no_duplicate_0x1001_tag(self) -> None:

Tests/test_shell_injection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def test_load_djpeg_filename(self, tmp_path: Path) -> None:
4444

4545
with Image.open(src_file) as im:
4646
assert isinstance(im, JpegImagePlugin.JpegImageFile)
47-
im.load_djpeg()
47+
with pytest.warns(DeprecationWarning, match="load_djpeg"):
48+
im.load_djpeg()
4849

4950
@pytest.mark.skipif(not netpbm_available(), reason="Netpbm not available")
5051
def test_save_netpbm_filename_bmp_mode(self, tmp_path: Path) -> None:

docs/deprecations.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,18 @@ Image getdata()
3030
identical, except that it returns a tuple of pixel values, instead of an internal
3131
Pillow data type.
3232

33+
34+
JpegImageFile.load_djpeg
35+
~~~~~~~~~~~~~~~~~~~~~~~~
36+
37+
.. deprecated:: 13.0.0
38+
39+
``JpegImageFile.load_djpeg`` has been deprecated, and will be removed in Pillow 14
40+
(2027-10-15).
41+
42+
Use the built-in JPEG decoder instead, or call ``djpeg`` directly and decode the
43+
resulting image with Pillow.
44+
3345
Removed features
3446
----------------
3547

docs/releasenotes/13.0.0.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,14 @@ ImageCms.ImageCmsProfile.product_name and .product_info
6969
Deprecations
7070
============
7171

72-
TODO
73-
^^^^
72+
JpegImageFile.load_djpeg
73+
^^^^^^^^^^^^^^^^^^^^^^^^
7474

75-
TODO
75+
``JpegImageFile.load_djpeg`` has been deprecated, and will be removed in Pillow 14
76+
(2027-10-15).
77+
78+
Use the built-in JPEG decoder instead, or call ``djpeg`` directly and decode the
79+
resulting image with Pillow.
7680

7781
API changes
7882
===========

src/PIL/JpegImagePlugin.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
from ._binary import i32be as i32
4949
from ._binary import o8
5050
from ._binary import o16be as o16
51+
from ._deprecate import deprecate
5152
from .JpegPresets import presets
5253

5354
TYPE_CHECKING = False
@@ -467,6 +468,11 @@ def draft(
467468

468469
def load_djpeg(self) -> None:
469470
# ALTERNATIVE: handle JPEGs via the IJG command line utilities
471+
deprecate(
472+
"load_djpeg",
473+
14,
474+
action="Use the built-in JPEG decoder instead, or call djpeg yourself.",
475+
)
470476

471477
f, path = tempfile.mkstemp()
472478
os.close(f)

0 commit comments

Comments
 (0)