mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-17 18:14:55 -04: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:
parent
774bd324b8
commit
87dea02b02
@ -356,7 +356,7 @@ e.g.
|
|||||||
{{ .Content }}
|
{{ .Content }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
## Files
|
## Files
|
||||||
|
|
||||||
### readDir
|
### 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!"`
|
`{{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
|
## Math
|
||||||
|
|
||||||
<table class="table table-bordered">
|
<table class="table table-bordered">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user