sigal icon indicating copy to clipboard operation
sigal copied to clipboard

Feature request: support for SVG image files

Open Lucas-C opened this issue 1 month ago • 3 comments

Hi.

I would like to build a galery of SVG images using sigal.

Currently this does not seem supported:

  1. I added '.svg' to the img_extensions setting
  2. I ran sigal build -v using an input folder with SVG images

Error produced:

ERROR: Failed to generate thumbnail: cannot identify image file '.../alakol_beach_1.svg'
...
INFO: Output album : <Album>(path='.', title='assets')
ERROR: Could not read size of .../alakol_beach_1.svg due to UnidentifiedImageError("cannot identify image file .../alakol_beach_1.svg'")
ERROR: Could not open image .../alakol_beach_1.svg metadata: cannot identify image file '.../groddle/alakol_beach_1.svg'
Traceback (most recent call last):
  File "/tmp/svg-sigal/venv/bin/sigal", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/tmp/svg-sigal/venv/lib/python3.12/site-packages/click/core.py", line 1462, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/svg-sigal/venv/lib/python3.12/site-packages/click/core.py", line 1383, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/tmp/svg-sigal/venv/lib/python3.12/site-packages/click/core.py", line 1850, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/svg-sigal/venv/lib/python3.12/site-packages/click/core.py", line 1246, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/svg-sigal/venv/lib/python3.12/site-packages/click/core.py", line 814, in invoke
    return callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/svg-sigal/venv/lib/python3.12/site-packages/sigal/__main__.py", line 191, in build
    gal.build(force=force_album if len(force_album) else force)
  File "/tmp/svg-sigal/venv/lib/python3.12/site-packages/sigal/gallery.py", line 916, in build
    album_list_writer.write(album)
  File "/tmp/svg-sigal/venv/lib/python3.12/site-packages/sigal/writer.py", line 158, in write
    page = self.template.render(**context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/svg-sigal/venv/lib/python3.12/site-packages/jinja2/environment.py", line 1295, in render
    self.environment.handle_exception()
  File "/tmp/svg-sigal/venv/lib/python3.12/site-packages/jinja2/environment.py", line 942, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/tmp/svg-sigal/venv/lib/python3.12/site-packages/sigal/themes/photoswipe/templates/album_list.html", line 1, in top-level template code
    {% extends "base.html" %}
  File "/tmp/svg-sigal/venv/lib/python3.12/site-packages/sigal/themes/photoswipe/templates/base.html", line 78,in top-level template code
    {% block content %}{% endblock %}
^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/svg-sigal/venv/lib/python3.12/site-packages/sigal/themes/photoswipe/templates/album_list.html", line 8, in block 'content'
    <img src="{{ alb.thumbnail }}" class="album_thumb"
^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/svg-sigal/venv/lib/python3.12/site-packages/jinja2/environment.py", line 490, in getattr
    return getattr(obj, attribute)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/svg-sigal/venv/lib/python3.12/site-packages/sigal/gallery.py", line 612, in thumbnail
    if size["width"] > size["height"]:
       ~~~~^^^^^^^^^
KeyError: 'width'

Lucas-C avatar Oct 27 '25 16:10 Lucas-C

It seems pillow doesn't support SVG (maybe it will at some point): https://pillow.readthedocs.io/en/latest/handbook/image-file-formats.html https://github.com/python-pillow/Pillow/issues/3509

saimn avatar Oct 27 '25 20:10 saimn

I think maybe sigal should not try to create thumbnails for SVG files, and simply display the SVG images as the thumbnail 🙂

The thumbsup gallery is also planning to handle SVG images this way: https://github.com/thumbsup/thumbsup/issues/165

Lucas-C avatar Oct 27 '25 21:10 Lucas-C

Seems a good idea.

saimn avatar Oct 28 '25 19:10 saimn