Use the magick executable from IMv7 preferentially

This commit is contained in:
Kovid Goyal 2021-02-04 11:34:32 +05:30
parent e5ef9d9062
commit 7eba3b6cbc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -121,7 +121,12 @@ def run_imagemagick(path: str, cmd: Sequence[str], keep_stdout: bool = True) ->
def identify(path: str) -> ImageData: def identify(path: str) -> ImageData:
import json import json
q = '{"fmt":"%m","canvas":"%g","transparency":"%A","gap":"%T","index":"%p","size":"%wx%h","dpi":"%xx%y"},' q = '{"fmt":"%m","canvas":"%g","transparency":"%A","gap":"%T","index":"%p","size":"%wx%h","dpi":"%xx%y"},'
p = run_imagemagick(path, ['identify', '-format', q, '--', path]) exe = find_exe('magick')
if exe:
cmd = [exe, 'identify']
else:
cmd = ['identify']
p = run_imagemagick(path, cmd + ['-format', q, '--', path])
data = json.loads(b'[' + p.stdout.rstrip(b',') + b']') data = json.loads(b'[' + p.stdout.rstrip(b',') + b']')
first = data[0] first = data[0]
frames = list(map(Frame, data)) frames = list(map(Frame, data))
@ -144,10 +149,15 @@ def render_image(
import tempfile import tempfile
has_multiple_frames = len(m) > 1 has_multiple_frames = len(m) > 1
get_multiple_frames = has_multiple_frames and not only_first_frame get_multiple_frames = has_multiple_frames and not only_first_frame
exe = find_exe('magick')
if exe:
cmd = [exe, 'convert']
else:
exe = find_exe('convert') exe = find_exe('convert')
if exe is None: if exe is None:
raise OSError('Failed to find the ImageMagick convert executable, make sure it is present in PATH') raise OSError('Failed to find the ImageMagick convert executable, make sure it is present in PATH')
cmd = [exe, '-background', 'none', '--', path] cmd = [exe]
cmd += ['-background', 'none', '--', path]
if only_first_frame and has_multiple_frames: if only_first_frame and has_multiple_frames:
cmd[-1] += '[0]' cmd[-1] += '[0]'
scaled = False scaled = False