From 1f3b456ac9dde628a34e3603a1461e5fe6fd7b62 Mon Sep 17 00:00:00 2001 From: Louis Sautier Date: Thu, 19 Aug 2021 01:14:48 +0200 Subject: [PATCH 1/3] tests: don't expect ImageMagick to compress TIFF files by default This is no longer the case with ImageMagick 7. --- src/img2pdf_test.py | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/src/img2pdf_test.py b/src/img2pdf_test.py index bdb8c7d..33252c8 100755 --- a/src/img2pdf_test.py +++ b/src/img2pdf_test.py @@ -1154,7 +1154,6 @@ def png_rgb8_img(tmp_normal_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "8" ), str(identify) @@ -1204,7 +1203,6 @@ def png_rgb16_img(tmp_normal16_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "16" @@ -1258,7 +1256,6 @@ def png_rgba8_img(tmp_path_factory, tmp_alpha_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "8" ), str(identify) @@ -1309,7 +1306,6 @@ def png_rgba16_img(tmp_alpha_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "16" @@ -1376,7 +1372,6 @@ def png_gray8a_img(tmp_path_factory, tmp_alpha_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "8" ), str(identify) @@ -1439,7 +1434,6 @@ def png_gray16a_img(tmp_path_factory, tmp_alpha_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "16" @@ -1494,7 +1488,6 @@ def png_interlaced_img(tmp_path_factory, tmp_normal_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "8" ), str(identify) @@ -1546,7 +1539,6 @@ def png_gray1_img(tmp_path_factory, tmp_gray1_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "1" ), str(identify) @@ -1597,7 +1589,6 @@ def png_gray2_img(tmp_path_factory, tmp_gray2_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "2" ), str(identify) @@ -1648,7 +1639,6 @@ def png_gray4_img(tmp_path_factory, tmp_gray4_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "4" ), str(identify) @@ -1699,7 +1689,6 @@ def png_gray8_img(tmp_path_factory, tmp_gray8_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "8" ), str(identify) @@ -1750,7 +1739,6 @@ def png_gray16_img(tmp_path_factory, tmp_gray16_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "16" @@ -1802,7 +1790,6 @@ def png_palette1_img(tmp_path_factory, tmp_palette1_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "1" ), str(identify) @@ -1853,7 +1840,6 @@ def png_palette2_img(tmp_path_factory, tmp_palette2_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "2" ), str(identify) @@ -1904,7 +1890,6 @@ def png_palette4_img(tmp_path_factory, tmp_palette4_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "4" ), str(identify) @@ -1955,7 +1940,6 @@ def png_palette8_img(tmp_path_factory, tmp_palette8_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "8" ), str(identify) @@ -2265,7 +2249,6 @@ def tiff_float_img(tmp_path_factory, tmp_normal_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("quantum:format") == "floating-point" @@ -2318,7 +2301,6 @@ def tiff_cmyk8_img(tmp_path_factory, tmp_normal_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -2376,7 +2358,6 @@ def tiff_cmyk16_img(tmp_path_factory, tmp_normal_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -2424,7 +2405,6 @@ def tiff_rgb8_img(tmp_path_factory, tmp_normal_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -2477,7 +2457,6 @@ def tiff_rgb12_img(tmp_path_factory, tmp_normal16_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -2530,7 +2509,6 @@ def tiff_rgb14_img(tmp_path_factory, tmp_normal16_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -2579,7 +2557,6 @@ def tiff_rgb16_img(tmp_path_factory, tmp_normal16_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -2628,7 +2605,6 @@ def tiff_rgba8_img(tmp_path_factory, tmp_alpha_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unassociated" ), str(identify) @@ -2677,7 +2653,6 @@ def tiff_rgba16_img(tmp_path_factory, tmp_alpha_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unassociated" ), str(identify) @@ -2724,7 +2699,6 @@ def tiff_gray1_img(tmp_path_factory, tmp_gray1_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -2772,7 +2746,6 @@ def tiff_gray2_img(tmp_path_factory, tmp_gray2_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -2820,7 +2793,6 @@ def tiff_gray4_img(tmp_path_factory, tmp_gray4_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -2868,7 +2840,6 @@ def tiff_gray8_img(tmp_path_factory, tmp_gray8_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -2916,7 +2887,6 @@ def tiff_gray16_img(tmp_path_factory, tmp_gray16_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -2968,7 +2938,6 @@ def tiff_multipage_img(tmp_path_factory, tmp_normal_png, tmp_inverse_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -3009,7 +2978,6 @@ def tiff_multipage_img(tmp_path_factory, tmp_normal_png, tmp_inverse_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -3059,7 +3027,6 @@ def tiff_palette1_img(tmp_path_factory, tmp_palette1_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -3108,7 +3075,6 @@ def tiff_palette2_img(tmp_path_factory, tmp_palette2_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -3157,7 +3123,6 @@ def tiff_palette4_img(tmp_path_factory, tmp_palette4_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -3205,7 +3170,6 @@ def tiff_palette8_img(tmp_path_factory, tmp_palette8_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("tiff:alpha") == "unspecified" ), str(identify) @@ -3735,7 +3699,6 @@ def png_icc_img(tmp_icc_png): "x": 0, "y": 0, }, str(identify) - assert identify[0]["image"].get("compression") == "Zip", str(identify) assert ( identify[0]["image"].get("properties", {}).get("png:IHDR.bit-depth-orig") == "8" ), str(identify) -- 2.39.2 From 152f6fb629581ab2f45a3b520f9468e99b0bc6b8 Mon Sep 17 00:00:00 2001 From: Louis Sautier Date: Thu, 19 Aug 2021 01:14:13 +0200 Subject: [PATCH 2/3] tests: look for sRGB.icc in several paths, skip related tests if not found Always use Ghostscript's sRGB.icc. --- .travis.yml | 1 - src/img2pdf_test.py | 31 +++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 564cb37..8f18940 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,7 +13,6 @@ matrix: - netpbm - ghostscript - mupdf-tools - - icc-profiles-free - name: "python 3.9 Windows" os: windows language: shell # 'language: python' is an error on Travis CI Windows diff --git a/src/img2pdf_test.py b/src/img2pdf_test.py index 33252c8..6e866be 100755 --- a/src/img2pdf_test.py +++ b/src/img2pdf_test.py @@ -20,6 +20,21 @@ import warnings import json import pathlib +ICC_PROFILE = None +ICC_PROFILE_PATHS = ( + # Debian + "/usr/share/color/icc/ghostscript/srgb.icc", + # Fedora + "/usr/share/ghostscript/iccprofiles/srgb.icc", + # Archlinux and Gentoo + "/usr/share/ghostscript/*/iccprofiles/srgb.icc", +) +for glob in ICC_PROFILE_PATHS: + for path in pathlib.Path("/").glob(glob.lstrip("/")): + if path.is_file(): + ICC_PROFILE = path + break + HAVE_MUTOOL = True try: ver = subprocess.check_output(["mutool", "-v"], stderr=subprocess.STDOUT) @@ -304,11 +319,9 @@ def compare(im1, im2, exact, icc, cmyk): else: iccargs = [] if icc: - profile = "/usr/share/color/icc/sRGB.icc" - if not os.path.isfile(profile): - warnings.warn(profile + " not present, skipping checks...") - return - iccargs = ["-profile", profile] + if ICC_PROFILE is None: + pytest.skip("Could not locate an ICC profile") + iccargs = ["-profile", ICC_PROFILE] psnr = subprocess.run( ["compare"] + iccargs @@ -421,10 +434,8 @@ def compare_pdfimages_png(tmpdir, img, pdf, exact=True, icc=False): ) else: if icc: - profile = "/usr/share/color/icc/ghostscript/srgb.icc" - if not os.path.isfile(profile): - warnings.warn(profile + " not present, skipping checks...") - return + if ICC_PROFILE is None: + pytest.skip("Could not locate an ICC profile") psnr = subprocess.run( [ "compare", @@ -432,7 +443,7 @@ def compare_pdfimages_png(tmpdir, img, pdf, exact=True, icc=False): "PSNR", "(", "-profile", - profile, + ICC_PROFILE, "-depth", "8", str(img), -- 2.39.2 From 635b08c321d83544af0d4266cd4ef2e4869beb3b Mon Sep 17 00:00:00 2001 From: Louis Sautier Date: Thu, 19 Aug 2021 13:59:16 +0200 Subject: [PATCH 3/3] README: fix CI URLs --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 3c3e08a..7dda3ad 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -[![Travis Status](https://travis-ci.org/josch/img2pdf.svg?branch=master)](https://travis-ci.org/josch/img2pdf) -[![Appveyor Status](https://ci.appveyor.com/api/projects/status/2kws3wkqvi526llj/branch/master?svg=true)](https://ci.appveyor.com/project/josch/img2pdf/branch/master) +[![Travis Status](https://travis-ci.com/josch/img2pdf.svg?branch=main)](https://app.travis-ci.com/josch/img2pdf) +[![Appveyor Status](https://ci.appveyor.com/api/projects/status/2kws3wkqvi526llj/branch/main?svg=true)](https://ci.appveyor.com/project/josch/img2pdf/branch/main) img2pdf ======= -- 2.39.2