Skip to content

Commit

Permalink
Merge pull request #7 from opeik/main
Browse files Browse the repository at this point in the history
Add svg support to img shortcode
  • Loading branch information
justint committed Nov 15, 2021
2 parents 067a744 + a9b0f76 commit 84984fe
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions templates/shortcodes/img.html
Expand Up @@ -14,26 +14,29 @@
{% set img_path = path %}
{% endif %}

{% set image_quality = 90 %}
{% if quality %}
{% set image_quality = quality %}
{% endif %}

{% if extended_width_pct %}
{% if extended_width_pct == -1 %}
{# adjust extended width to container width #}
{% set extended_width_pct = 0.042 %}
{% if path is not ending_with(".svg") %}
{% set resize = true %}
{% set image_quality = 90 %}
{% if quality %}
{% set image_quality = quality %}
{% endif %}
{% set _width = config.extra.images.max_width - figure_width %}
{% set extended_width = (extended_width_pct * _width + figure_width) | round | int %}
{% if extended_width > config.extra.images.max_width %}
{% set extended_width = config.extra.images.max_width %}

{% if extended_width_pct %}
{% if extended_width_pct == -1 %}
{# adjust extended width to container width #}
{% set extended_width_pct = 0.042 %}
{% endif %}
{% set _width = config.extra.images.max_width - figure_width %}
{% set extended_width = (extended_width_pct * _width + figure_width) | round | int %}
{% if extended_width > config.extra.images.max_width %}
{% set extended_width = config.extra.images.max_width %}
{% endif %}
{% set resized_image = resize_image(path=img_path, width=extended_width, op="fit_width", quality=image_quality) %}
{% else %}
{% set resized_image = resize_image(path=img_path, width=figure_width, op="fit_width", quality=image_quality) %}
{% endif %}
{% set resized_image = resize_image(path=img_path, width=extended_width, op="fit_width", quality=image_quality) %}
{% else %}
{% set resized_image = resize_image(path=img_path, width=figure_width, op="fit_width", quality=image_quality) %}
{% endif %}
<figure {% if extended_width_pct %}class="extended-figure"{% endif %}>
<img src="{{ resized_image.url }}" class="{% if class %}{{class}}{% endif %}" {% if alt %}alt="{{alt}}"{% endif %}/>
<img src="{% if resize %}{{ resized_image.url }}{% else %}{{ path }}{% endif %}" class="{% if class %}{{class}}{% endif %}" {% if alt %}alt="{{alt}}"{% endif %}/>
{% if caption %}<figcaption>{{ caption | safe }}</figcaption>{% endif %}
</figure>
</figure>

0 comments on commit 84984fe

Please sign in to comment.