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