images.Filter
將一個或多個 影像濾鏡 應用於給定的影像。
要應用單一濾鏡:
{{ with resources.Get "images/original.jpg" }}
{{ with images.Filter images.Grayscale . }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
要應用兩個或更多濾鏡,從左到右執行:
{{ $filters := slice
images.Grayscale
(images.GaussianBlur 8)
}}
{{ with resources.Get "images/original.jpg" }}
{{ with images.Filter $filters . }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
您也可以使用 Filter
方法來對 Resource
物件應用影像濾鏡。
範例
{{ with resources.Get "images/original.jpg" }}
{{ with images.Filter images.Grayscale . }}
<img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
{{ end }}
{{ end }}
Original

Processed

影像濾鏡
使用任何這些濾鏡與 images.Filter
函數,或與 Resource
物件的 Filter
方法一起使用。