mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
Add a set of image filters
With this you can do variants of this: ``` {{ $img := resources.Get "images/misc/3-jenny.jpg" }} {{ $img := $img.Resize "300x" }} {{ $g1 := $img.Filter images.Grayscale }} {{ $g2 := $img | images.Filter (images.Saturate 30) (images.GaussianBlur 3) }} ``` Fixes #6255
This commit is contained in:
@@ -16,8 +16,6 @@ package internal
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
bp "github.com/gohugoio/hugo/bufferpool"
|
||||
|
||||
"github.com/mitchellh/hashstructure"
|
||||
)
|
||||
|
||||
@@ -44,18 +42,23 @@ func (k ResourceTransformationKey) Value() string {
|
||||
return k.Name
|
||||
}
|
||||
|
||||
sb := bp.GetBuffer()
|
||||
defer bp.PutBuffer(sb)
|
||||
return k.Name + "_" + HashString(k.elements...)
|
||||
|
||||
sb.WriteString(k.Name)
|
||||
for _, element := range k.elements {
|
||||
hash, err := hashstructure.Hash(element, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
sb.WriteString("_")
|
||||
sb.WriteString(strconv.FormatUint(hash, 10))
|
||||
}
|
||||
|
||||
// HashString returns a hash from the given elements.
|
||||
// It will panic if the hash cannot be calculated.
|
||||
func HashString(elements ...interface{}) string {
|
||||
var o interface{}
|
||||
if len(elements) == 1 {
|
||||
o = elements[0]
|
||||
} else {
|
||||
o = elements
|
||||
}
|
||||
|
||||
return sb.String()
|
||||
hash, err := hashstructure.Hash(o, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return strconv.FormatUint(hash, 10)
|
||||
}
|
||||
|
Reference in New Issue
Block a user