hugo: github.com/gohugoio/hugo/resources/images Index | Files | Directories

package images

import "github.com/gohugoio/hugo/resources/images"

Package images provides template functions for manipulating images.

Index

Package Files

color.go config.go filters.go image.go resampling.go smartcrop.go

func AddColorToPalette Uses

func AddColorToPalette(c color.Color, p color.Palette) color.Palette

AddColorToPalette adds c as the first color in p if not already there. Note that it does no additional checks, so callers must make sure that the palette is valid for the relevant format.

func IsOpaque Uses

func IsOpaque(img image.Image) bool

IsOpaque returns false if the image has alpha channel and there is at least 1 pixel that is not (fully) opaque.

func ReplaceColorInPalette Uses

func ReplaceColorInPalette(c color.Color, p color.Palette)

ReplaceColorInPalette will replace the color in palette p closest to c in Euclidean R,G,B,A space with c.

func ToFilters Uses

func ToFilters(in interface{}) []gift.Filter

type ExifConfig Uses

type ExifConfig struct {

    // Regexp matching the Exif fields you want from the (massive) set of Exif info
    // available. As we cache this info to disk, this is for performance and
    // disk space reasons more than anything.
    // If you want it all, put ".*" in this config setting.
    // Note that if neither this or ExcludeFields is set, Hugo will return a small
    // default set.
    IncludeFields string

    // Regexp matching the Exif fields you want to exclude. This may be easier to use
    // than IncludeFields above, depending on what you want.
    ExcludeFields string

    // Hugo extracts the "photo taken" date/time into .Date by default.
    // Set this to true to turn it off.
    DisableDate bool

    // Hugo extracts the "photo taken where" (GPS latitude and longitude) into
    // .Long and .Lat. Set this to true to turn it off.
    DisableLatLong bool
}

type Filters Uses

type Filters struct {
}

func (*Filters) Brightness Uses

func (*Filters) Brightness(percentage interface{}) gift.Filter

Brightness creates a filter that changes the brightness of an image. The percentage parameter must be in range (-100, 100).

func (*Filters) ColorBalance Uses

func (*Filters) ColorBalance(percentageRed, percentageGreen, percentageBlue interface{}) gift.Filter

ColorBalance creates a filter that changes the color balance of an image. The percentage parameters for each color channel (red, green, blue) must be in range (-100, 500).

func (*Filters) Colorize Uses

func (*Filters) Colorize(hue, saturation, percentage interface{}) gift.Filter

Colorize creates a filter that produces a colorized version of an image. The hue parameter is the angle on the color wheel, typically in range (0, 360). The saturation parameter must be in range (0, 100). The percentage parameter specifies the strength of the effect, it must be in range (0, 100).

func (*Filters) Contrast Uses

func (*Filters) Contrast(percentage interface{}) gift.Filter

Contrast creates a filter that changes the contrast of an image. The percentage parameter must be in range (-100, 100).

func (*Filters) Gamma Uses

func (*Filters) Gamma(gamma interface{}) gift.Filter

Gamma creates a filter that performs a gamma correction on an image. The gamma parameter must be positive. Gamma = 1 gives the original image. Gamma less than 1 darkens the image and gamma greater than 1 lightens it.

func (*Filters) GaussianBlur Uses

func (*Filters) GaussianBlur(sigma interface{}) gift.Filter

GaussianBlur creates a filter that applies a gaussian blur to an image.

func (*Filters) Grayscale Uses

func (*Filters) Grayscale() gift.Filter

Grayscale creates a filter that produces a grayscale version of an image.

func (*Filters) Hue Uses

func (*Filters) Hue(shift interface{}) gift.Filter

Hue creates a filter that rotates the hue of an image. The hue angle shift is typically in range -180 to 180.

func (*Filters) Invert Uses

func (*Filters) Invert() gift.Filter

Invert creates a filter that negates the colors of an image.

func (*Filters) Pixelate Uses

func (*Filters) Pixelate(size interface{}) gift.Filter

Pixelate creates a filter that applies a pixelation effect to an image.

func (*Filters) Saturation Uses

func (*Filters) Saturation(percentage interface{}) gift.Filter

Saturation creates a filter that changes the saturation of an image.

func (*Filters) Sepia Uses

func (*Filters) Sepia(percentage interface{}) gift.Filter

Sepia creates a filter that produces a sepia-toned version of an image.

func (*Filters) Sigmoid Uses

func (*Filters) Sigmoid(midpoint, factor interface{}) gift.Filter

Sigmoid creates a filter that changes the contrast of an image using a sigmoidal function and returns the adjusted image. It's a non-linear contrast change useful for photo adjustments as it preserves highlight and shadow detail.

func (*Filters) UnsharpMask Uses

func (*Filters) UnsharpMask(sigma, amount, threshold interface{}) gift.Filter

UnsharpMask creates a filter that sharpens an image. The sigma parameter is used in a gaussian function and affects the radius of effect. Sigma must be positive. Sharpen radius roughly equals 3 * sigma. The amount parameter controls how much darker and how much lighter the edge borders become. Typically between 0.5 and 1.5. The threshold parameter controls the minimum brightness change that will be sharpened. Typically between 0 and 0.05.

type Format Uses

type Format int

Format is an image file format.

const (
    JPEG Format = iota + 1
    PNG
    GIF
    TIFF
    BMP
)

func ImageFormatFromExt Uses

func ImageFormatFromExt(ext string) (Format, bool)

func (Format) DefaultExtension Uses

func (f Format) DefaultExtension() string

DefaultExtension returns the default file extension of this format, starting with a dot. For example: .jpg for JPEG

func (Format) MediaType Uses

func (f Format) MediaType() media.Type

MediaType returns the media type of this image, e.g. image/jpeg for JPEG

func (Format) RequiresDefaultQuality Uses

func (f Format) RequiresDefaultQuality() bool

RequiresDefaultQuality returns if the default quality needs to be applied to images of this format

func (Format) SupportsTransparency Uses

func (f Format) SupportsTransparency() bool

SupportsTransparency reports whether it supports transparency in any form.

type Image Uses

type Image struct {
    Format Format
    Proc   *ImageProcessor
    Spec   Spec
    // contains filtered or unexported fields
}

func NewImage Uses

func NewImage(f Format, proc *ImageProcessor, img image.Image, s Spec) *Image

func (*Image) EncodeTo Uses

func (i *Image) EncodeTo(conf ImageConfig, img image.Image, w io.Writer) error

func (*Image) Height Uses

func (i *Image) Height() int

Height returns i's height.

func (*Image) InitConfig Uses

func (i *Image) InitConfig(r io.Reader) error

InitConfig reads the image config from the given reader.

func (*Image) Width Uses

func (i *Image) Width() int

Width returns i's width.

func (Image) WithImage Uses

func (i Image) WithImage(img image.Image) *Image

func (Image) WithSpec Uses

func (i Image) WithSpec(s Spec) *Image

type ImageConfig Uses

type ImageConfig struct {
    // This defines the output format of the output image. It defaults to the source format
    TargetFormat Format

    Action string

    // If set, this will be used as the key in filenames etc.
    Key string

    // Quality ranges from 1 to 100 inclusive, higher is better.
    // This is only relevant for JPEG images.
    // Default is 75.
    Quality int

    // Rotate rotates an image by the given angle counter-clockwise.
    // The rotation will be performed first.
    Rotate int

    // Used to fill any transparency.
    // When set in site config, it's used when converting to a format that does
    // not support transparency.
    // When set per image operation, it's used even for formats that does support
    // transparency.
    BgColor    color.Color
    BgColorStr string

    Width  int
    Height int

    Filter    gift.Resampling
    FilterStr string

    Anchor    gift.Anchor
    AnchorStr string
}

ImageConfig holds configuration to create a new image from an existing one, resize etc.

func DecodeImageConfig Uses

func DecodeImageConfig(action, config string, defaults Imaging) (ImageConfig, error)

func (ImageConfig) GetKey Uses

func (i ImageConfig) GetKey(format Format) string

type ImageProcessor Uses

type ImageProcessor struct {
    Cfg ImagingConfig
    // contains filtered or unexported fields
}

func NewImageProcessor Uses

func NewImageProcessor(cfg ImagingConfig) (*ImageProcessor, error)

func (*ImageProcessor) ApplyFiltersFromConfig Uses

func (p *ImageProcessor) ApplyFiltersFromConfig(src image.Image, conf ImageConfig) (image.Image, error)

func (*ImageProcessor) DecodeExif Uses

func (p *ImageProcessor) DecodeExif(r io.Reader) (*exif.Exif, error)

func (*ImageProcessor) Filter Uses

func (p *ImageProcessor) Filter(src image.Image, filters ...gift.Filter) (image.Image, error)

func (*ImageProcessor) GetDefaultImageConfig Uses

func (p *ImageProcessor) GetDefaultImageConfig(action string) ImageConfig

type Imaging Uses

type Imaging struct {
    // Default image quality setting (1-100). Only used for JPEG images.
    Quality int

    // Resample filter to use in resize operations..
    ResampleFilter string

    // The anchor to use in Fill. Default is "smart", i.e. Smart Crop.
    Anchor string

    // Default color used in fill operations (e.g. "fff" for white).
    BgColor string

    Exif ExifConfig
}

Imaging contains default image processing configuration. This will be fetched from site (or language) config.

type ImagingConfig Uses

type ImagingConfig struct {
    BgColor color.Color

    // Config as provided by the user.
    Cfg Imaging
}

func DecodeConfig Uses

func DecodeConfig(m map[string]interface{}) (ImagingConfig, error)

type Spec Uses

type Spec interface {
    // Loads the image source.
    ReadSeekCloser() (hugio.ReadSeekCloser, error)
}

Directories

PathSynopsis
exif

Package images imports 23 packages (graph) and is imported by 12 packages. Updated 2019-12-20. Refresh now. Tools for package owners.