lottie_convert.py can't find assets because it looks in wrong directory

This has been tested on python-lottie 0.6.5, but the issue still seems to be in the latest master (I did a quick skim over the history).

When I'm running lottie_convert.py to convert to PNG, it will try to find assets of the lottie file in the current directory, rather than relative to the lottie file:

My terminal is here:

$ pwd
/Users/JannikGM/Projects/lottie-test

I'm running this:

$ lottie_convert.py /Users/JannikGM/Desktop/lottie_animation.json lottie_convert.png
Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1507, in open_local_file
    stats = os.stat(localfile)
FileNotFoundError: [Errno 2] No such file or directory: '/Users/JannikGM/Projects/lottie-test/images/img_0.png'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):ƒ
  File "/usr/local/bin/lottie_convert.py", line 158, in <module>
    exporter.process(an, outfile, **o_options)
  File "/Users/JannikGM/Library/Python/3.8/lib/python/site-packages/lottie/parsers/baseporter.py", line 18, in process
    return self.callback(*a, **kw)
  File "/Users/JannikGM/Library/Python/3.8/lib/python/site-packages/lottie/exporters/cairo.py", line 17, in export_png
    _export_cairo(cairosvg.svg2png, animation, fp, frame, dpi)
  File "/Users/JannikGM/Library/Python/3.8/lib/python/site-packages/lottie/exporters/cairo.py", line 12, in _export_cairo
    func(file_obj=intermediate, write_to=fp, dpi=dpi)
  File "/usr/local/lib/python3.8/site-packages/cairosvg/__init__.py", line 66, in svg2png
    return surface.PNGSurface.convert(
  File "/usr/local/lib/python3.8/site-packages/cairosvg/surface.py", line 146, in convert
    instance = cls(
  File "/usr/local/lib/python3.8/site-packages/cairosvg/surface.py", line 212, in __init__
    self.draw(tree)
  File "/usr/local/lib/python3.8/site-packages/cairosvg/surface.py", line 449, in draw
    self.draw(child)
  File "/usr/local/lib/python3.8/site-packages/cairosvg/surface.py", line 449, in draw
    self.draw(child)
  File "/usr/local/lib/python3.8/site-packages/cairosvg/surface.py", line 383, in draw
    TAGS[node.tag](self, node)
  File "/usr/local/lib/python3.8/site-packages/cairosvg/defs.py", line 377, in use
    surface.draw(tree)
  File "/usr/local/lib/python3.8/site-packages/cairosvg/surface.py", line 383, in draw
    TAGS[node.tag](self, node)
  File "/usr/local/lib/python3.8/site-packages/cairosvg/image.py", line 44, in image
    image_bytes = node.fetch_url(url, 'image/*')
  File "/usr/local/lib/python3.8/site-packages/cairosvg/parser.py", line 258, in fetch_url
    return read_url(url, self.url_fetcher, resource_type)
  File "/usr/local/lib/python3.8/site-packages/cairosvg/url.py", line 159, in read_url
    return url_fetcher(url, resource_type)
  File "/usr/local/lib/python3.8/site-packages/cairosvg/url.py", line 100, in fetch
    return urlopen(Request(url, headers=HTTP_HEADERS)).read()
  File "/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 525, in open
    response = self._open(req, data)
  File "/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 542, in _open
    result = self._call_chain(self.handle_open, protocol, protocol +
  File "/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1485, in file_open
    return self.open_local_file(req)
  File "/usr/local/Cellar/python@3.8/3.8.6/Frameworks/Python.framework/Versions/3.8/lib/python3.8/urllib/request.py", line 1524, in open_local_file
    raise URLError(exp)
urllib.error.URLError: <urlopen error [Errno 2] No such file or directory: '/Users/JannikGM/Projects/lottie-test/images/img_0.png'>

So:

  • lottie file is in /Users/JannikGM/Desktop/lottie_animation.json
    • lottie file asset exists in /Users/JannikGM/Desktop/ images/img_0.png
  • python-lottie is ran from /Users/JannikGM/Projects/lottie-test
    • python-lottie looks for /Users/JannikGM/Projects/lottie-test/ images/img_0.png (which does not exist)

The lottie file has been exported using After Effects / bodymovin.