summaryrefslogtreecommitdiffstats
path: root/resources
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-06-14 08:14:39 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2023-06-14 09:21:22 +0200
commit21d17566a3c21a33e78a6aa0bec9c82687eea6fb (patch)
tree02941bbe7c4a99a6b79836ec324d03552be8e90d /resources
parent35e9b3ed1ef96452fc6c721c6022862d2cf3bc70 (diff)
Fix .Width and .Height for animated gifs
Fixes #11079
Diffstat (limited to 'resources')
-rw-r--r--resources/image_test.go5
-rw-r--r--resources/images/image.go3
-rw-r--r--resources/integration_test.go20
3 files changed, 19 insertions, 9 deletions
diff --git a/resources/image_test.go b/resources/image_test.go
index 779bacf71..de32f0628 100644
--- a/resources/image_test.go
+++ b/resources/image_test.go
@@ -658,11 +658,12 @@ func TestImageOperationsGolden(t *testing.T) {
// A simple Gif file (no animation).
orig := fetchImageForSpec(spec, c, "gohugoio-card.gif")
- for _, resizeSpec := range []string{"100x", "220x"} {
- resized, err := orig.Resize(resizeSpec)
+ for _, width := range []int{100, 220} {
+ resized, err := orig.Resize(fmt.Sprintf("%dx", width))
c.Assert(err, qt.IsNil)
rel := resized.RelPermalink()
c.Assert(rel, qt.Not(qt.Equals), "")
+ c.Assert(resized.Width(), qt.Equals, width)
}
// Animated GIF
diff --git a/resources/images/image.go b/resources/images/image.go
index 530057d80..672e8578f 100644
--- a/resources/images/image.go
+++ b/resources/images/image.go
@@ -377,6 +377,9 @@ type imageConfig struct {
}
func imageConfigFromImage(img image.Image) image.Config {
+ if giphy, ok := img.(Giphy); ok {
+ return giphy.GIF().Config
+ }
b := img.Bounds()
return image.Config{Width: b.Max.X, Height: b.Max.Y}
}
diff --git a/resources/integration_test.go b/resources/integration_test.go
index 92abcb612..543c264dc 100644
--- a/resources/integration_test.go
+++ b/resources/integration_test.go
@@ -34,15 +34,21 @@ title: "My Bundle"
---
-- content/mybundle/pixel.png --
iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==
+-- content/mybundle/giphy.gif --
+sourcefilename: testdata/giphy.gif
-- layouts/foo.html --
-- layouts/index.html --
{{ $p := site.GetPage "mybundle"}}
{{ $img := $p.Resources.Get "pixel.png" }}
-{{ $gif := $img.Resize "1x1 gif" }}
-{{ $bmp := $img.Resize "1x1 bmp" }}
+{{ $giphy := $p.Resources.Get "giphy.gif" }}
+{{ $gif := $img.Resize "1x2 gif" }}
+{{ $bmp := $img.Resize "2x3 bmp" }}
+{{ $anigif := $giphy.Resize "4x5" }}
-gif: {{ $gif.RelPermalink }}|{{ $gif.MediaType }}|
-bmp: {{ $bmp.RelPermalink }}|{{ $bmp.MediaType }}|
+
+gif: {{ $gif.RelPermalink }}|}|{{ $gif.Width }}|{{ $gif.Height }}|{{ $gif.MediaType }}|
+bmp: {{ $bmp.RelPermalink }}|}|{{ $bmp.Width }}|{{ $bmp.Height }}|{{ $bmp.MediaType }}|
+anigif: {{ $anigif.RelPermalink }}|{{ $anigif.Width }}|{{ $anigif.Height }}|{{ $anigif.MediaType }}|
`
b := hugolib.NewIntegrationTestBuilder(
@@ -55,9 +61,9 @@ bmp: {{ $bmp.RelPermalink }}|{{ $bmp.MediaType }}|
assertImages := func() {
b.AssertFileContent("public/index.html", `
- gif: /mybundle/pixel_hu8aa3346827e49d756ff4e630147c42b5_70_1x1_resize_box_3.gif|image/gif|
- bmp: /mybundle/pixel_hu8aa3346827e49d756ff4e630147c42b5_70_1x1_resize_box_3.bmp|image/bmp|
-
+ gif: /mybundle/pixel_hu8aa3346827e49d756ff4e630147c42b5_70_1x2_resize_box_3.gif|}|1|2|image/gif|
+ bmp: /mybundle/pixel_hu8aa3346827e49d756ff4e630147c42b5_70_2x3_resize_box_3.bmp|}|2|3|image/bmp|
+ anigif: /mybundle/giphy_hu3eafc418e52414ace6236bf1d31f82e1_52213_4x5_resize_box_1.gif|4|5|image/gif|
`)
}