Version check fails on 'modern' ImageMagick versions #204

Open
opened 2024-09-08 20:17:53 +00:00 by gms · 0 comments

Recent ImageMagick versions such as 7.1.1-33 (e.g. as available on Fedora 39) yield a deprecation warning like this, when invoking the convert command:

[ins] In [84]: subprocess.check_output(['magick', 'convert'] + ["-version"], stderr=subprocess.STDOUT, text=True).splitlines()[0]
Out[22]: 'WARNING: The convert command is deprecated in IMv7, use "magick"'

[ins] In [85]: subprocess.check_output(['convert'] + ["-version"], stderr=subprocess.STDOUT, text=True).splitlines()[0]
Out[23]: 'WARNING: The convert command is deprecated in IMv7, use "magick"'

Thus, the code in

Lines 80 to 110 in 819b366
for prog in ["convert", "compare", "identify"]:
try:
subprocess.check_call([prog] + ["-version"], stderr=subprocess.STDOUT)
globals()[prog.upper()] = [prog]
except subprocess.CalledProcessError:
globals()[prog.upper()] = ["magick", prog]
HAVE_IMAGEMAGICK_MODERN = True
HAVE_EXACT_CMYK8 = True
try:
ver = subprocess.check_output(CONVERT + ["-version"], stderr=subprocess.STDOUT)
m = re.fullmatch(
r"Version: ImageMagick ([0-9.]+-[0-9]+) .*", ver.split(b"\n")[0].decode("utf8")
)
if m is None:
HAVE_IMAGEMAGICK_MODERN = False
HAVE_EXACT_CMYK8 = False
else:
if parse_version(m.group(1)) < parse_version("6.9.10-12"):
HAVE_IMAGEMAGICK_MODERN = False
if parse_version(m.group(1)) < parse_version("7.1.0-48"):
HAVE_EXACT_CMYK8 = False
except FileNotFoundError:
HAVE_IMAGEMAGICK_MODERN = False
HAVE_EXACT_CMYK8 = False
except subprocess.CalledProcessError:
HAVE_IMAGEMAGICK_MODERN = False
HAVE_EXACT_CMYK8 = False
if not HAVE_IMAGEMAGICK_MODERN:
warnings.warn("imagemagick >= 6.9.10-12 not available, skipping certain checks...")

erroneously warns (and misidentifies the version) like this (on such systems, such as recent Fedora versions):

/builddir/build/BUILD/python-img2pdf-0.5.1-build/img2pdf-0.5.1/src/img2pdf_test.py:109: UserWarning: imagemagick >= 6.9.10-12 not available, skipping certain checks...

My quick fix for Fedora Rawhide:

--- img2pdf-0.5.1/src/img2pdf_test.py.orig      2024-09-08 20:41:48.379173360 +0200
+++ img2pdf-0.5.1/src/img2pdf_test.py   2024-09-08 21:55:33.381512253 +0200
@@ -77,12 +77,9 @@
 if not HAVE_PDFIMAGES_CMYK:
     warnings.warn("pdfimages >= 0.42.0 not available, skipping CMYK checks...")
 
-for prog in ["convert", "compare", "identify"]:
-    try:
-        subprocess.check_call([prog] + ["-version"], stderr=subprocess.STDOUT)
-        globals()[prog.upper()] = [prog]
-    except subprocess.CalledProcessError:
-        globals()[prog.upper()] = ["magick", prog]
+for prog in ["compare", "identify"]:
+    globals()[prog.upper()] = ["magick", prog]
+globals()['CONVERT'] = ['magick']
 
 HAVE_IMAGEMAGICK_MODERN = True
 HAVE_EXACT_CMYK8 = True
@@ -5546,7 +5543,7 @@
     )
     jpg_rot_png = tmpdir / "jpg_rot.png"
     subprocess.check_call(
-        CONVERT + ["-rotate", "90", str(jpg_rot_pnm), str(jpg_rot_png)]
+        CONVERT + [str(jpg_rot_pnm), "-rotate", "90", str(jpg_rot_png)]
     )
     jpg_rot_pnm.unlink()
     compare_ghostscript(tmpdir, jpg_rot_png, jpg_rot_pdf)

Apparently, the whole ImageMagick convert situation is unnecessary complex and utterly confusing, cf. e.g.:

https://github.com/ImageMagick/ImageMagick/discussions/7366

AFAICS, note to myself, stuff like this doesn't qualify ImageMagick for new projects or continued personal usage ...

Recent ImageMagick versions such as 7.1.1-33 (e.g. as available on Fedora 39) yield a deprecation warning like this, when invoking the `convert` command: ``` [ins] In [84]: subprocess.check_output(['magick', 'convert'] + ["-version"], stderr=subprocess.STDOUT, text=True).splitlines()[0] Out[22]: 'WARNING: The convert command is deprecated in IMv7, use "magick"' [ins] In [85]: subprocess.check_output(['convert'] + ["-version"], stderr=subprocess.STDOUT, text=True).splitlines()[0] Out[23]: 'WARNING: The convert command is deprecated in IMv7, use "magick"' ``` Thus, the code in https://gitlab.mister-muffin.de/josch/img2pdf/src/commit/819b366bf5751e475b32b8f4670fed819fb5e7af/src/img2pdf_test.py#L80-L110 erroneously warns (and misidentifies the version) like this (on such systems, such as recent Fedora versions): ``` /builddir/build/BUILD/python-img2pdf-0.5.1-build/img2pdf-0.5.1/src/img2pdf_test.py:109: UserWarning: imagemagick >= 6.9.10-12 not available, skipping certain checks... ``` My quick fix for Fedora Rawhide: ``` --- img2pdf-0.5.1/src/img2pdf_test.py.orig 2024-09-08 20:41:48.379173360 +0200 +++ img2pdf-0.5.1/src/img2pdf_test.py 2024-09-08 21:55:33.381512253 +0200 @@ -77,12 +77,9 @@ if not HAVE_PDFIMAGES_CMYK: warnings.warn("pdfimages >= 0.42.0 not available, skipping CMYK checks...") -for prog in ["convert", "compare", "identify"]: - try: - subprocess.check_call([prog] + ["-version"], stderr=subprocess.STDOUT) - globals()[prog.upper()] = [prog] - except subprocess.CalledProcessError: - globals()[prog.upper()] = ["magick", prog] +for prog in ["compare", "identify"]: + globals()[prog.upper()] = ["magick", prog] +globals()['CONVERT'] = ['magick'] HAVE_IMAGEMAGICK_MODERN = True HAVE_EXACT_CMYK8 = True @@ -5546,7 +5543,7 @@ ) jpg_rot_png = tmpdir / "jpg_rot.png" subprocess.check_call( - CONVERT + ["-rotate", "90", str(jpg_rot_pnm), str(jpg_rot_png)] + CONVERT + [str(jpg_rot_pnm), "-rotate", "90", str(jpg_rot_png)] ) jpg_rot_pnm.unlink() compare_ghostscript(tmpdir, jpg_rot_png, jpg_rot_pdf) ``` --- Apparently, the whole ImageMagick convert situation is unnecessary complex and utterly confusing, cf. e.g.: https://github.com/ImageMagick/ImageMagick/discussions/7366 AFAICS, note to myself, stuff like this doesn't qualify ImageMagick for new projects or continued personal usage ...
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: josch/img2pdf#204
No description provided.