diff --git a/layouts/shortcodes/figure.html b/layouts/shortcodes/figure.html
index fbf3da1..4d82ead 100644
--- a/layouts/shortcodes/figure.html
+++ b/layouts/shortcodes/figure.html
@@ -5,21 +5,25 @@
{{ $.Scratch.Set "width" .Width -}}
{{ $.Scratch.Set "height" .Height -}}
{{ end -}}
-{{ if (.Get "width") -}}
+{{ if and (.Get "width") (.Get "height") -}}
{{ $.Scratch.Set "width" (int (.Get "width")) -}}
+ {{ $.Scratch.Set "height" (int (.Get "height")) -}}
+{{ else if (.Get "width") -}}
+ {{ $.Scratch.Set "width" (int (.Get "width")) -}}
+ {{ if lt ($.Scratch.Get "width") ($.Scratch.Get "realwidth") -}}
+ {{ $height := (mul ($.Scratch.Get "realheight") (div (add ($.Scratch.Get "width") 0.0) ($.Scratch.Get "realwidth"))) -}}
+ {{ $.Scratch.Set "height" (math.Round $height) -}}
+ {{ end -}}
+{{ else if (.Get "height") -}}
+ {{ $.Scratch.Set "height" (int (.Get "height")) -}}
+ {{ if lt ($.Scratch.Get "height") ($.Scratch.Get "realheight") -}}
+ {{ $width := (mul ($.Scratch.Get "realwidth") (div (add ($.Scratch.Get "height") 0.0) ($.Scratch.Get "realheight"))) -}}
+ {{ $.Scratch.Set "width" (math.Round $width) -}}
+ {{ end -}}
{{ else if and $maxwidth (lt $maxwidth ($.Scratch.Get "width")) -}}
{{ $.Scratch.Set "width" $maxwidth -}}
-{{ end -}}
-{{ if lt ($.Scratch.Get "width") ($.Scratch.Get "realwidth") -}}
{{ $height := (mul ($.Scratch.Get "realheight") (div (add ($.Scratch.Get "width") 0.0) ($.Scratch.Get "realwidth"))) -}}
- {{ $.Scratch.Set "height" (int $height) -}}
-{{ end -}}
-{{ if (.Get "height") -}}
- {{ $.Scratch.Set "height" (int (.Get "height")) -}}
-{{ end -}}
-{{ if lt ($.Scratch.Get "height") ($.Scratch.Get "realheight") -}}
- {{ $width := (mul ($.Scratch.Get "realwidth") (div (add ($.Scratch.Get "height") 0.0) ($.Scratch.Get "realheight"))) -}}
- {{ $.Scratch.Set "width" (int $width) -}}
+ {{ $.Scratch.Set "height" (math.Round $height) -}}
{{ end -}}
{{ with .Get "link" }}{{ end -}}