kovidgoyal/kitty · error · OutdatedImageMagick

Unexpected output filename: {x!r} produced by ImageMagick co

Error message

Unexpected output filename: {x!r} produced by ImageMagick command: {last_imagemagick_cmd}

What it means

Raised (as OutdatedImageMagick) when render_image cannot parse the filename ImageMagick generated for a frame. IM names outputs like prefix-N-WxH+X+Y.mode; the code extracts width/height/canvas via split and positive_int. Any parse failure means IM emitted an unexpected naming scheme, typically from an outdated ImageMagick version.

Source

Thrown at kittens/tui/images.py:269

    with tempfile.TemporaryDirectory(dir=os.path.dirname(output_prefix)) as tdir:
        output_template = os.path.join(tdir, f'im-%[filename:f].{m.mode}')
        if get_multiple_frames:
            cmd.append('+adjoin')
        run_imagemagick(path, cmd + [output_template])
        unseen = {x.index for x in m}
        for x in os.listdir(tdir):
            try:
                parts = x.split('.', 1)[0].split('-')
                index = int(parts[-1])
                unseen.discard(index)
                f = ans.frames[index]
                f.width, f.height = map(positive_int, parts[1:3])
                sz, pos = parts[3].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 OutdatedImageMagick(f'Unexpected output filename: {x!r} produced by ImageMagick command: {last_imagemagick_cmd}')
            f.path = output_prefix + f'-{index}.{m.mode}'
            os.rename(os.path.join(tdir, x), f.path)
            check_resize(f)
    f = ans.frames[0]
    if f.width != ans.width or f.height != ans.height:
        with open(f.path, 'r+b') as ff:
            data = ff.read()
            ff.seek(0)
            ff.truncate()
            cd = create_canvas(data, f.width, f.canvas_x, f.canvas_y, ans.width, ans.height, 3 if ans.mode == 'rgb' else 4)
            ff.write(cd)
    if get_multiple_frames:
        if unseen:
            raise ConvertFailed(path, f'Failed to render {len(unseen)} out of {len(m)} frames of animation')
    elif not ans.frames[0].path:
        raise ConvertFailed(path, 'Failed to render image')

    return ans

View on GitHub (pinned to 6d5d0c4406)

Solutions

  1. Upgrade to a recent ImageMagick (7.x, using 'magick')
  2. Check 'convert --version' / 'magick --version' and remove stale shims earlier in PATH
  3. Catch OutdatedImageMagick and inform the user to update ImageMagick

Example fix

# before
img = render_image(path, width=80)  # OutdatedImageMagick
# after
# brew upgrade imagemagick  (or apt install --only-upgrade imagemagick)
img = render_image(path, width=80)
Defensive patterns

Strategy: try-catch

Validate before calling

import subprocess
def imagemagick_version_ok() -> bool:
    for exe in ('magick', 'convert'):
        try:
            out = subprocess.run([exe, '--version'], capture_output=True, text=True).stdout
            if 'ImageMagick' in out:
                return True
        except FileNotFoundError:
            continue
    return False

Try / catch

from kittens.tui.images import OutdatedImageMagick
try:
    img = render_image(path, width=80)
except OutdatedImageMagick:
    show_banner('Please upgrade ImageMagick to render images')
    img = None

Prevention

When it happens

Trigger: Calling render_image() with an ImageMagick whose identify/convert writes frame filenames in a format that doesn't match 'name-N-WxH+X+Y.ext', or where dimensions are non-positive/non-numeric, causing the parsing block to raise and be re-raised as OutdatedImageMagick.

Common situations: Very old ImageMagick 6.x releases; distro packages with patched filename behavior; ImageMagick forks or wrappers named 'convert' that use different output naming.

Related errors


AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27). Data as JSON: /api/errors/cd9b53b7eabff299. Report an issue: GitHub.