From 618a3a30144d7788abe3dc14fce5953c60ca745b Mon Sep 17 00:00:00 2001 From: stereobooster Date: Thu, 5 Oct 2023 11:51:06 +0200 Subject: [PATCH] Improve extraction of SVG dimensions --- layouts/partials/picture.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/layouts/partials/picture.html b/layouts/partials/picture.html index 98a10a47..c82bbd21 100644 --- a/layouts/partials/picture.html +++ b/layouts/partials/picture.html @@ -44,18 +44,18 @@ {{ $height := ""}} {{ if eq .MediaType.SubType "svg" }} {{ $svgContent := $resource.Content }} - {{ range (findRESubmatch `width=["']?(\d*)` $svgContent 1) }} + {{ range (findRESubmatch `]*width=["']([.0-9]*)["'a-zA-Z]` $svgContent 1) }} {{ $width = index . 1 }} {{ end }} - {{ range (findRESubmatch `height=["']?(\d*)` $svgContent 1) }} + {{ range (findRESubmatch `]*height=["']([.0-9]*)["'a-zA-Z]` $svgContent 1) }} {{ $height = index . 1 }} {{ end }} {{ if (eq "" $width $height) }} - {{ range (findRESubmatch `viewBox=["']?(\d*) (\d*) (\d*) (\d*)` $svgContent 1) }} - {{ $width = index . 3 }} - {{ $height = index . 4 }} - {{ end }} + {{ range (findRESubmatch `]*viewBox=["']?([.0-9]*) ([.0-9]*) ([.0-9]*) ([.0-9]*)` $svgContent 1) }} + {{ $width = index . 3 }} + {{ $height = index . 4 }} {{ end }} + {{ end }} {{ else }} {{ $width = .Width }} {{ $height = .Height }}