mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-13 20:24:00 +02:00
Add animated GIF support
Note that this is for GIFs only (and not Webp). Fixes #5030
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"image"
|
||||
"image/color"
|
||||
"image/draw"
|
||||
"image/gif"
|
||||
_ "image/gif"
|
||||
_ "image/png"
|
||||
"io"
|
||||
@@ -346,6 +347,15 @@ func (i *imageResource) decodeImageConfig(action, spec string) (images.ImageConf
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
type giphy struct {
|
||||
image.Image
|
||||
gif *gif.GIF
|
||||
}
|
||||
|
||||
func (g *giphy) GIF() *gif.GIF {
|
||||
return g.gif
|
||||
}
|
||||
|
||||
// DecodeImage decodes the image source into an Image.
|
||||
// This an internal method and may change.
|
||||
func (i *imageResource) DecodeImage() (image.Image, error) {
|
||||
@@ -354,6 +364,14 @@ func (i *imageResource) DecodeImage() (image.Image, error) {
|
||||
return nil, fmt.Errorf("failed to open image for decode: %w", err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if i.Format == images.GIF {
|
||||
g, err := gif.DecodeAll(f)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to decode gif: %w", err)
|
||||
}
|
||||
return &giphy{gif: g, Image: g.Image[0]}, nil
|
||||
}
|
||||
img, _, err := image.Decode(f)
|
||||
return img, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user