diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html
index 8ed3f41..efcac00 100644
--- a/layouts/shortcodes/figure.html
+++ b/layouts/shortcodes/figure.html
@@ -39,8 +39,13 @@
{{ if $size -}}
{{ $image := $resource.Resize $size -}}
{{ $src = $image.RelPermalink -}}
- {{ $width = $image.Width -}}
- {{ $height = $image.Height -}}
+ {{ if or $width $height -}}
+ {{ $realwidth = $image.Width -}}
+ {{ $realheight = $image.Height -}}
+ {{ else -}}
+ {{ $width = $image.Width -}}
+ {{ $height = $image.Height -}}
+ {{ end -}}
{{ if $srcset -}}
{{ $srcsetw = $srcsetw | append (printf "%s %sw" $src (strings.TrimRight "x" $size)) -}}
{{ end -}}
diff --git a/layouts/shortcodes/img.html b/layouts/shortcodes/img.html
index 9ae48e2..64eb94e 100644
--- a/layouts/shortcodes/img.html
+++ b/layouts/shortcodes/img.html
@@ -35,8 +35,13 @@
{{ if $size -}}
{{ $image := $resource.Resize $size -}}
{{ $src = $image.RelPermalink -}}
- {{ $width = $image.Width -}}
- {{ $height = $image.Height -}}
+ {{ if or $width $height -}}
+ {{ $realwidth = $image.Width -}}
+ {{ $realheight = $image.Height -}}
+ {{ else -}}
+ {{ $width = $image.Width -}}
+ {{ $height = $image.Height -}}
+ {{ end -}}
{{ if $srcset -}}
{{ $srcsetw = $srcsetw | append (printf "%s %sw" $src (strings.TrimRight "x" $size)) -}}
{{ end -}}