HUGO
Menu
GitHub 87548 stars Mastodon

Filter

適用於圖像,將一個或多個圖像濾鏡應用於給定圖像資源。

Syntax

RESOURCE.Filter FILTER...

Returns

images.ImageResource

此方法可用於 全局資源頁面資源遠程資源

將一個或多個 圖像濾鏡 應用於給定圖像。

要應用單個濾鏡:

{{ with resources.Get "images/original.jpg" }}
  {{ with .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 .Filter $filters }}
    <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
  {{ end }}
{{ end }}

您也可以使用 images.Filter 函數應用圖像濾鏡。

示例

{{ with resources.Get "images/original.jpg" }}
  {{ with .Filter images.Grayscale }}
    <img src="{{ .RelPermalink }}" width="{{ .Width }}" height="{{ .Height }}" alt="">
  {{ end }}
{{ end }}

Original

Zion National Park

Processed

Zion National Park

圖像濾鏡

將此方法與任何這些濾鏡一起使用。

images.AutoOrient
Returns an image filter that rotates and flips an image as needed per its Exif orientation tag.
images.Brightness
Returns an image filter that changes the brightness of an image.
images.ColorBalance
Returns an image filter that changes the color balance of an image.
images.Colorize
Returns an image filter that produces a colorized version of an image.
images.Contrast
Returns an image filter that changes the contrast of an image.
images.Dither
Returns an image filter that dithers an image.
images.Gamma
Returns an image filter that performs gamma correction on an image.
images.GaussianBlur
Returns an image filter that applies a gaussian blur to an image.
images.Grayscale
Returns an image filter that produces a grayscale version of an image.
images.Hue
Returns an image filter that rotates the hue of an image.
images.Invert
Returns an image filter that negates the colors of an image.
images.Mask
Returns an image filter that applies a mask to the source image.
images.Opacity
Returns an image filter that changes the opacity of an image.
images.Overlay
Returns an image filter that overlays the source image at the given coordinates, relative to the upper left corner.
images.Padding
Returns an image filter that resizes the image canvas without resizing the image.
images.Pixelate
Returns an image filter that applies a pixelation effect to an image.
images.Process
Returns an image filter that processes an image according to the given processing specification.
images.QR
Encodes the given text into a QR code using the specified options, returning an image resource.
images.Saturation
Returns an image filter that changes the saturation of an image.
images.Sepia
Returns an image filter that produces a sepia-toned version of an image.
images.Sigmoid
Returns an image filter that changes the contrast of an image using a sigmoidal function.
images.Text
Returns an image filter that adds text to an image.
images.UnsharpMask
Returns an image filter that sharpens an image.

Last updated: January 1, 0001
Improve this page