From 87dea02b02847bb214415ec664ee0c3a8ec67d18 Mon Sep 17 00:00:00 2001 From: Tristan Rice Date: Wed, 16 Nov 2016 04:00:45 -0800 Subject: [PATCH] tpl: Add imageConfig function Add imageConfig function which calls image.DecodeConfig and returns the height, width and color mode of the image. (#2677) This allows for more advanced image shortcodes and templates such as those required by AMP. layouts/shortcodes/amp-img.html ``` {{ $src := .Get "src" }} {{ $config := imageConfig (printf "/static/%s" $src) }} ``` --- content/templates/functions.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/content/templates/functions.md b/content/templates/functions.md index 417e2cdb2..bee82e21f 100644 --- a/content/templates/functions.md +++ b/content/templates/functions.md @@ -356,7 +356,7 @@ e.g. {{ .Content }} {{ end }} -## Files +## Files ### readDir @@ -372,6 +372,16 @@ Reads a file from disk and converts it into a string. Note that the filename mus `{{readFile "README.txt"}}` → `"Hugo Rocks!"` +### imageConfig +Parses the image and returns the height, width and color model. + +e.g. +``` +{{ with (imageConfig "favicon.ico") }} +favicon.ico: {{.Width}} x {{.Height}} +{{ end }} +``` + ## Math