33import itertools
44import logging
55import os
6+ import re
67from collections import namedtuple
78from ctypes import c_float
89
910import pytest
10- from PIL import Image , ImageFilter , TiffImagePlugin , TiffTags
11+ from PIL import Image , ImageFilter , TiffImagePlugin , TiffTags , features
1112
1213from .helper import (
1314 assert_image_equal ,
@@ -47,6 +48,9 @@ def _assert_noerr(self, tmp_path, im):
4748
4849
4950class TestFileLibTiff (LibTiffTestCase ):
51+ def test_version (self ):
52+ assert re .search (r"\d+\.\d+\.\d+$" , features .version_codec ("libtiff" ))
53+
5054 def test_g4_tiff (self , tmp_path ):
5155 """Test the ordinary file path load path"""
5256
@@ -299,9 +303,6 @@ def check_tags(tiffinfo):
299303 )
300304 continue
301305
302- if libtiff and isinstance (value , bytes ):
303- value = value .decode ()
304-
305306 assert reloaded_value == value
306307
307308 # Test with types
@@ -322,6 +323,17 @@ def check_tags(tiffinfo):
322323 )
323324 TiffImagePlugin .WRITE_LIBTIFF = False
324325
326+ def test_xmlpacket_tag (self , tmp_path ):
327+ TiffImagePlugin .WRITE_LIBTIFF = True
328+
329+ out = str (tmp_path / "temp.tif" )
330+ hopper ().save (out , tiffinfo = {700 : b"xmlpacket tag" })
331+ TiffImagePlugin .WRITE_LIBTIFF = False
332+
333+ with Image .open (out ) as reloaded :
334+ if 700 in reloaded .tag_v2 :
335+ assert reloaded .tag_v2 [700 ] == b"xmlpacket tag"
336+
325337 def test_int_dpi (self , tmp_path ):
326338 # issue #1765
327339 im = hopper ("RGB" )
@@ -448,6 +460,14 @@ def test_compressions(self, tmp_path):
448460 assert size_compressed > size_jpeg
449461 assert size_jpeg > size_jpeg_30
450462
463+ def test_tiff_jpeg_compression (self , tmp_path ):
464+ im = hopper ("RGB" )
465+ out = str (tmp_path / "temp.tif" )
466+ im .save (out , compression = "tiff_jpeg" )
467+
468+ with Image .open (out ) as reloaded :
469+ assert reloaded .info ["compression" ] == "jpeg"
470+
451471 def test_quality (self , tmp_path ):
452472 im = hopper ("RGB" )
453473 out = str (tmp_path / "temp.tif" )
@@ -667,6 +687,26 @@ def test_read_icc(self):
667687 TiffImagePlugin .READ_LIBTIFF = False
668688 assert icc == icc_libtiff
669689
690+ def test_write_icc (self , tmp_path ):
691+ def check_write (libtiff ):
692+ TiffImagePlugin .WRITE_LIBTIFF = libtiff
693+
694+ with Image .open ("Tests/images/hopper.iccprofile.tif" ) as img :
695+ icc_profile = img .info ["icc_profile" ]
696+
697+ out = str (tmp_path / "temp.tif" )
698+ img .save (out , icc_profile = icc_profile )
699+ with Image .open (out ) as reloaded :
700+ assert icc_profile == reloaded .info ["icc_profile" ]
701+
702+ libtiffs = []
703+ if Image .core .libtiff_support_custom_tags :
704+ libtiffs .append (True )
705+ libtiffs .append (False )
706+
707+ for libtiff in libtiffs :
708+ check_write (libtiff )
709+
670710 def test_multipage_compression (self ):
671711 with Image .open ("Tests/images/compression.tif" ) as im :
672712
0 commit comments