Better error message when ImageMagick does not write correct output filenames
This commit is contained in:
parent
82934b84d6
commit
02d29d4816
@ -118,8 +118,13 @@ class NoImageMagick(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
last_imagemagick_cmd: Sequence[str] = ()
|
||||||
|
|
||||||
|
|
||||||
def run_imagemagick(path: str, cmd: Sequence[str], keep_stdout: bool = True) -> CompletedProcess:
|
def run_imagemagick(path: str, cmd: Sequence[str], keep_stdout: bool = True) -> CompletedProcess:
|
||||||
|
global last_imagemagick_cmd
|
||||||
import subprocess
|
import subprocess
|
||||||
|
last_imagemagick_cmd = cmd
|
||||||
try:
|
try:
|
||||||
p = subprocess.run(cmd, stdout=subprocess.PIPE if keep_stdout else subprocess.DEVNULL, stderr=subprocess.PIPE)
|
p = subprocess.run(cmd, stdout=subprocess.PIPE if keep_stdout else subprocess.DEVNULL, stderr=subprocess.PIPE)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
@ -222,14 +227,17 @@ def render_image(
|
|||||||
run_imagemagick(path, cmd + [output_template])
|
run_imagemagick(path, cmd + [output_template])
|
||||||
unseen = {x.index for x in m}
|
unseen = {x.index for x in m}
|
||||||
for x in os.listdir(tdir):
|
for x in os.listdir(tdir):
|
||||||
parts = x.split('.', 1)[0].split('-')
|
try:
|
||||||
index = int(parts[-1])
|
parts = x.split('.', 1)[0].split('-')
|
||||||
unseen.discard(index)
|
index = int(parts[-1])
|
||||||
f = ans.frames[index]
|
unseen.discard(index)
|
||||||
f.width, f.height = map(positive_int, parts[1:3])
|
f = ans.frames[index]
|
||||||
sz, pos = parts[3].split('+', 1)
|
f.width, f.height = map(positive_int, parts[1:3])
|
||||||
f.canvas_width, f.canvas_height = map(positive_int, sz.split('x', 1))
|
sz, pos = parts[3].split('+', 1)
|
||||||
f.canvas_x, f.canvas_y = map(int, pos.split('+', 1))
|
f.canvas_width, f.canvas_height = map(positive_int, sz.split('x', 1))
|
||||||
|
f.canvas_x, f.canvas_y = map(int, pos.split('+', 1))
|
||||||
|
except Exception:
|
||||||
|
raise ValueError(f'Unexpected output filename: {x!r} produced by ImageMagick command: {last_imagemagick_cmd}')
|
||||||
f.path = output_prefix + f'-{index}.{m.mode}'
|
f.path = output_prefix + f'-{index}.{m.mode}'
|
||||||
os.rename(os.path.join(tdir, x), f.path)
|
os.rename(os.path.join(tdir, x), f.path)
|
||||||
check_resize(f)
|
check_resize(f)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user