mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-26 22:04:32 +02:00
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:
committed by
Bjørn Erik Pedersen
parent
950034db5c
commit
a49f838cd0
@@ -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">
|
||||
|
Reference in New Issue
Block a user