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) }}

<amp-img src="{{$src}}"
           height="{{$config.Height}}"
           width="{{$config.Width}}"
           layout="responsive">
</amp-img>
```
This commit is contained in:
Tristan Rice
2016-11-16 04:00:45 -08:00
committed by Bjørn Erik Pedersen
parent 950034db5c
commit a49f838cd0
4 changed files with 184 additions and 2 deletions

View File

@@ -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
<table class="table table-bordered">