Skip to content

Support get_image_metadata for SVG #769

@mre

Description

@mre

Bug Report

My blog mostly uses SVG as an image format. This way, images are crisp while still being small. @killercup and me recently noticed that posts get redrawn when an image gets loaded on the page. Here is an example. Although a minor annoyance, it's not very visually pleasing.

One idea was to set the width and height of the image and there is the handy get_image_metadata builtin, but it does not support SVG yet.

Environment

Zola version: 0.8.0

Expected Behavior

The following shortcode should work for SVG:

{% set meta = get_image_metadata(path=page.path~src) %}
<img src="{{ src }}" height="{{ meta.height }}" width="{{ meta.width }}" />

Current Behavior

Error: Failed to render content of snippet.
Reason: The Decoder does not support the image format Image format image/"svg" is not supported.

Suggestion

For the case where the SVG file has a viewBox attribute set, we could use that extract the width and height from it. In case the attribute is not set, we could throw and error with a hint about the missing viewBox.

Alternative approach

Previously I used lqip on my blog, but I did not port it when I moved from cobalt.rs to zola.
I could dig that up again, but I was hoping to avoid that if possible and rather go with a more general solution.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions