diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index c26c503c4..4414dbe5e 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -1,5 +1,4 @@ import base64 -import distutils.version import io import itertools import logging @@ -272,12 +271,8 @@ class TestFileLibTiff(LibTiffTestCase): ) } - libtiff_version = TiffImagePlugin._libtiff_version() - libtiffs = [False] - if distutils.version.StrictVersion( - libtiff_version - ) >= distutils.version.StrictVersion("4.0"): + if Image.core.libtiff_support_custom_tags: libtiffs.append(True) for libtiff in libtiffs: diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index 47b69a003..fa8c852c2 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -38,7 +38,6 @@ # # See the README file for information on usage and redistribution. # -import distutils.version import io import itertools import os @@ -264,10 +263,6 @@ def _limit_rational(val, max_val): return n_d[::-1] if inv else n_d -def _libtiff_version(): - return Image.core.libtiff_version.split("\n")[0].split("Version ")[1] - - ## # Wrapper for TIFF IFDs. @@ -1559,11 +1554,10 @@ def _save(im, fp, filename): # Custom items are supported for int, float, unicode, string and byte # values. Other types and tuples require a tagtype. if tag not in TiffTags.LIBTIFF_CORE: - if TiffTags.lookup(tag).type == TiffTags.UNDEFINED: - continue - if distutils.version.StrictVersion( - _libtiff_version() - ) < distutils.version.StrictVersion("4.0"): + if ( + TiffTags.lookup(tag).type == TiffTags.UNDEFINED + or not Image.core.libtiff_support_custom_tags + ): continue if tag in ifd.tagtype: diff --git a/src/_imaging.c b/src/_imaging.c index a55ebb64b..190b312bc 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -82,6 +82,12 @@ #include "zlib.h" #endif +#ifdef HAVE_LIBTIFF +#ifndef _TIFFIO_ +#include +#endif +#endif + #include "Imaging.h" #define _USE_MATH_DEFINES @@ -3961,6 +3967,15 @@ setup_module(PyObject* m) { { extern const char * ImagingTiffVersion(void); PyDict_SetItemString(d, "libtiff_version", PyUnicode_FromString(ImagingTiffVersion())); + + // Test for libtiff 4.0 or later, excluding libtiff 3.9.6 and 3.9.7 + PyObject* support_custom_tags; +#if TIFFLIB_VERSION >= 20111221 && TIFFLIB_VERSION != 20120218 && TIFFLIB_VERSION != 20120922 + support_custom_tags = Py_True; +#else + support_custom_tags = Py_False; +#endif + PyDict_SetItemString(d, "libtiff_support_custom_tags", support_custom_tags); } #endif