Skip to content

Commit a8c5d0d

Browse files
committed
Fix "image: unknown format" error
Fixes #14295
1 parent a94a941 commit a8c5d0d

File tree

15 files changed

+92
-47
lines changed

15 files changed

+92
-47
lines changed

‎hugolib/hugo_sites_multihost_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,9 @@ title: mybundle-en
207207
b.AssertFileExists("public/de/mybundle/pixel.png", true)
208208
b.AssertFileExists("public/en/mybundle/pixel.png", true)
209209

210-
b.AssertFileExists("public/de/mybundle/pixel_hu_58204cbc58507d74.png", true)
210+
b.AssertFileExists("public/de/mybundle/pixel_hu_c8522c65d73a0421.png", true)
211211
// failing test below
212-
b.AssertFileExists("public/en/mybundle/pixel_hu_58204cbc58507d74.png", true)
212+
b.AssertFileExists("public/en/mybundle/pixel_hu_c8522c65d73a0421.png", true)
213213
}
214214

215215
func TestMultihostResourceOneBaseURLWithSubPath(t *testing.T) {

‎hugolib/integrationtest_builder.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,16 @@ func (s *IntegrationTestBuilder) EditFileReplaceFunc(filename string, replacemen
720720
return s
721721
}
722722

723+
func (s *IntegrationTestBuilder) EditFileAppend(filename, contnt string) *IntegrationTestBuilder {
724+
absFilename := s.absFilename(filename)
725+
b, err := afero.ReadFile(s.fs.Source, absFilename)
726+
s.Assert(err, qt.IsNil)
727+
s.changedFiles = append(s.changedFiles, absFilename)
728+
oldContent := string(b)
729+
s.writeSource(absFilename, oldContent+contnt)
730+
return s
731+
}
732+
723733
func (s *IntegrationTestBuilder) EditFiles(filenameContent ...string) *IntegrationTestBuilder {
724734
for i := 0; i < len(filenameContent); i += 2 {
725735
filename, content := filepath.FromSlash(filenameContent[i]), filenameContent[i+1]

‎hugolib/pagesfromdata/pagesfromgotmpl_integration_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ docs/p1/sub/mymixcasetext2.txt
122122
"RelPermalink: /docs/p1/sub/mymixcasetext2.txt|Name: sub/mymixcasetext2.txt|",
123123
"RelPermalink: /mydata.yaml|Name: sub/data1.yaml|Title: Sub data|Params: map[]|",
124124
"Featured Image: /a/pixel.png|featured.png|",
125-
"Resized Featured Image: /a/pixel_hu_a32b3e361d55df1.png|10|",
125+
"Resized Featured Image: /a/pixel_hu_a354833fd576551d.png|10|",
126126
// Resource from string
127127
"RelPermalink: /docs/p1/mytext.txt|Name: textresource|Title: My Text Resource|Params: map[param1:param1v]|",
128128
// Dates

‎internal/warpc/webp_integration_test.go‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Resized RelPermalink: {{ $resized.RelPermalink }}|
6060

6161
b := hugolib.Test(t, files)
6262

63-
b.ImageHelper("public/gopher_hu_f8d20fe200599f16.webp").AssertFormat("webp")
63+
b.ImageHelper("public/gopher_hu_cc98ebaf742cba8e.webp").AssertFormat("webp")
6464
}
6565

6666
func TestWebPInvalid(t *testing.T) {
@@ -111,9 +111,9 @@ sourcefilename: ../../resources/testdata/giphy.gif
111111
// Source animated gif:
112112
// Frame durations in ms.
113113
giphyFrameDurations := []int{200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200}
114-
b.ImageHelper("public/giphy_hu_e4a5984f8835d617.webp").AssertFormat("webp").AssertIsAnimated(true).AssertLoopCount(0).AssertFrameDurations(giphyFrameDurations)
115-
b.ImageHelper("public/giphy_hu_87010e943ffb23b4.gif").AssertFormat("gif").AssertIsAnimated(true).AssertLoopCount(0).AssertFrameDurations(giphyFrameDurations)
116-
b.ImageHelper("public/giphy_hu_e4a5984f8835d617.webp").AssertFormat("webp").AssertIsAnimated(true).AssertLoopCount(0).AssertFrameDurations(giphyFrameDurations)
114+
115+
b.ImageHelper("public/giphy_hu_bb052284cc220165.webp").AssertFormat("webp").AssertIsAnimated(true).AssertLoopCount(0).AssertFrameDurations(giphyFrameDurations)
116+
b.ImageHelper("public/giphy_hu_c6b8060edf0363b1.gif").AssertFormat("gif").AssertIsAnimated(true).AssertLoopCount(0).AssertFrameDurations(giphyFrameDurations)
117117

118118
// Source animated webp:
119119
animFrameDurations := []int{80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, 80}

‎resources/image_test.go‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,28 +113,28 @@ func TestImageTransformBasic(t *testing.T) {
113113
assertWidthHeight(resizedAndRotated, 125, 200)
114114

115115
assertWidthHeight(resized, 300, 200)
116-
c.Assert(resized.RelPermalink(), qt.Equals, "/a/sunset_hu_d2115125d9324a79.jpg")
116+
c.Assert(resized.RelPermalink(), qt.Equals, "/a/sunset_hu_f4f15cdbaaca3b2d.jpg")
117117

118118
fitted, err := resized.Fit("50x50")
119119
c.Assert(err, qt.IsNil)
120-
c.Assert(fitted.RelPermalink(), qt.Equals, "/a/sunset_hu_c2c98e06123b048e.jpg")
120+
c.Assert(fitted.RelPermalink(), qt.Equals, "/a/sunset_hu_c9781e950a09210.jpg")
121121
assertWidthHeight(fitted, 50, 33)
122122

123123
// Check the MD5 key threshold
124124
fittedAgain, _ := fitted.Fit("10x20")
125125
fittedAgain, err = fittedAgain.Fit("10x20")
126126
c.Assert(err, qt.IsNil)
127-
c.Assert(fittedAgain.RelPermalink(), qt.Equals, "/a/sunset_hu_dc9e89c10109de72.jpg")
127+
c.Assert(fittedAgain.RelPermalink(), qt.Equals, "/a/sunset_hu_78c1665fdce5ec4d.jpg")
128128
assertWidthHeight(fittedAgain, 10, 7)
129129

130130
filled, err := image.Fill("200x100 bottomLeft")
131131
c.Assert(err, qt.IsNil)
132-
c.Assert(filled.RelPermalink(), qt.Equals, "/a/sunset_hu_b9f6d350738928fe.jpg")
132+
c.Assert(filled.RelPermalink(), qt.Equals, "/a/sunset_hu_b3e01daae854e587.jpg")
133133
assertWidthHeight(filled, 200, 100)
134134

135135
smart, err := image.Fill("200x100 smart")
136136
c.Assert(err, qt.IsNil)
137-
c.Assert(smart.RelPermalink(), qt.Equals, "/a/sunset_hu_6fd390e7b0d26f0b.jpg")
137+
c.Assert(smart.RelPermalink(), qt.Equals, "/a/sunset_hu_622a1375d91d9312.jpg")
138138
assertWidthHeight(smart, 200, 100)
139139

140140
// Check cache
@@ -144,12 +144,12 @@ func TestImageTransformBasic(t *testing.T) {
144144

145145
cropped, err := image.Crop("300x300 topRight")
146146
c.Assert(err, qt.IsNil)
147-
c.Assert(cropped.RelPermalink(), qt.Equals, "/a/sunset_hu_3df036e11f4ddd43.jpg")
147+
c.Assert(cropped.RelPermalink(), qt.Equals, "/a/sunset_hu_9016246670a22728.jpg")
148148
assertWidthHeight(cropped, 300, 300)
149149

150150
smartcropped, err := image.Crop("200x200 smart")
151151
c.Assert(err, qt.IsNil)
152-
c.Assert(smartcropped.RelPermalink(), qt.Equals, "/a/sunset_hu_12e2d26de89b464b.jpg")
152+
c.Assert(smartcropped.RelPermalink(), qt.Equals, "/a/sunset_hu_78e9677f68b821ed.jpg")
153153
assertWidthHeight(smartcropped, 200, 200)
154154

155155
// Check cache
@@ -216,15 +216,15 @@ func TestImageTransformFormat(t *testing.T) {
216216

217217
imagePng, err := image.Resize("450x png")
218218
c.Assert(err, qt.IsNil)
219-
c.Assert(imagePng.RelPermalink(), qt.Equals, "/a/sunset_hu_e8b9444dcf2e75ef.png")
219+
c.Assert(imagePng.RelPermalink(), qt.Equals, "/a/sunset_hu_63ccccb11ff4e285.png")
220220
c.Assert(imagePng.ResourceType(), qt.Equals, "image")
221221
assertExtWidthHeight(imagePng, ".png", 450, 281)
222222
c.Assert(imagePng.Name(), qt.Equals, "sunset.jpg")
223223
c.Assert(imagePng.MediaType().String(), qt.Equals, "image/png")
224224

225225
imageGif, err := image.Resize("225x gif")
226226
c.Assert(err, qt.IsNil)
227-
c.Assert(imageGif.RelPermalink(), qt.Equals, "/a/sunset_hu_f80842d4c3789345.gif")
227+
c.Assert(imageGif.RelPermalink(), qt.Equals, "/a/sunset_hu_6d1f23c09eddc748.gif")
228228
c.Assert(imageGif.ResourceType(), qt.Equals, "image")
229229
assertExtWidthHeight(imageGif, ".gif", 225, 141)
230230
c.Assert(imageGif.Name(), qt.Equals, "sunset.jpg")
@@ -247,7 +247,7 @@ func TestImagePermalinkPublishOrder(t *testing.T) {
247247
}()
248248

249249
check1 := func(img images.ImageResource) {
250-
resizedLink := "/a/sunset_hu_3910bca82e28c9d6.jpg"
250+
resizedLink := "/a/sunset_hu_3a097ae28aebc166.jpg"
251251
c.Assert(img.RelPermalink(), qt.Equals, resizedLink)
252252
assertImageFile(c, spec.PublishFs, resizedLink, 100, 50)
253253
}
@@ -288,12 +288,12 @@ func TestImageBugs(t *testing.T) {
288288
c.Assert(err, qt.IsNil)
289289
c.Assert(resized, qt.Not(qt.IsNil))
290290
c.Assert(resized.Width(), qt.Equals, 200)
291-
c.Assert(resized.RelPermalink(), qt.Equals, "/a/1234567890qwertyuiopasdfghjklzxcvbnm5to6eeeeee7via8eleph_hu_951d3980b18c52a9.jpg")
291+
c.Assert(resized.RelPermalink(), qt.Equals, "/a/1234567890qwertyuiopasdfghjklzxcvbnm5to6eeeeee7via8eleph_hu_a6f31c42e1afef07.jpg")
292292
resized, err = resized.Resize("100x")
293293
c.Assert(err, qt.IsNil)
294294
c.Assert(resized, qt.Not(qt.IsNil))
295295
c.Assert(resized.Width(), qt.Equals, 100)
296-
c.Assert(resized.RelPermalink(), qt.Equals, "/a/1234567890qwertyuiopasdfghjklzxcvbnm5to6eeeeee7via8eleph_hu_1daa203572ecd6ec.jpg")
296+
c.Assert(resized.RelPermalink(), qt.Equals, "/a/1234567890qwertyuiopasdfghjklzxcvbnm5to6eeeeee7via8eleph_hu_14e106419fe28039.jpg")
297297
})
298298

299299
// Issue #6137
@@ -391,7 +391,7 @@ func TestImageResize8BitPNG(t *testing.T) {
391391
resized, err := image.Resize("800x")
392392
c.Assert(err, qt.IsNil)
393393
c.Assert(resized.MediaType().Type, qt.Equals, "image/png")
394-
c.Assert(resized.RelPermalink(), qt.Equals, "/a/gohugoio_hu_fe2b762e9cac406c.png")
394+
c.Assert(resized.RelPermalink(), qt.Equals, "/a/gohugoio_hu_626cfc4db4222bfe.png")
395395
c.Assert(resized.Width(), qt.Equals, 800)
396396
}
397397

‎resources/images/config.go‎

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,9 @@ var (
6767
media.Builtin.WEBPType.SubType: WEBP,
6868
}
6969

70-
// Add or increment if changes to an image format's processing requires
71-
// re-generation.
72-
imageFormatsVersions = map[Format]int{
73-
PNG: 0,
74-
WEBP: 1, // Moved to WASM-based WebP encoder and decoder.
75-
GIF: 0,
76-
}
77-
7870
// Increment to mark all processed images as stale. Only use when absolutely needed.
79-
// See the finer grained smartCropVersionNumber and imageFormatsVersions.
80-
mainImageVersionNumber = 0
71+
// See the finer grained smartCropVersionNumber.
72+
mainImageVersionNumber = 1
8173
)
8274

8375
var anchorPositions = map[string]gift.Anchor{
@@ -328,10 +320,6 @@ func DecodeImageConfig(options []string, defaults *config.ConfigNamespace[Imagin
328320
options = append(options, strconv.Itoa(mainImageVersionNumber))
329321
}
330322

331-
if v, ok := imageFormatsVersions[sourceFormat]; ok && v > 0 {
332-
options = append(options, strconv.Itoa(v))
333-
}
334-
335323
if smartCropVersionNumber > 0 && c.Anchor == SmartCropAnchor {
336324
options = append(options, strconv.Itoa(smartCropVersionNumber))
337325
}

‎resources/images/config_test.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"testing"
2020

2121
qt "github.com/frankban/quicktest"
22-
"github.com/gohugoio/hugo/common/hashing"
2322
)
2423

2524
func TestDecodeConfig(t *testing.T) {
@@ -118,7 +117,7 @@ func TestDecodeImageConfig(t *testing.T) {
118117
t.Fatalf("[%d] err: %s", i, err)
119118
}
120119
expect := this.expect.(ImageConfig)
121-
expect.Key = hashing.HashStringHex(options)
120+
result.Key = ""
122121

123122
if fmt.Sprint(result) != fmt.Sprint(expect) {
124123
t.Fatalf("[%d] got\n%v\n but expected\n%v", i, result, expect)

‎resources/images/image.go‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,25 @@ func (f Format) MediaType() media.Type {
380380
}
381381
}
382382

383+
func (f Format) String() string {
384+
switch f {
385+
case JPEG:
386+
return "JPEG"
387+
case PNG:
388+
return "PNG"
389+
case GIF:
390+
return "GIF"
391+
case TIFF:
392+
return "TIFF"
393+
case BMP:
394+
return "BMP"
395+
case WEBP:
396+
return "WEBP"
397+
default:
398+
return "Unknown"
399+
}
400+
}
401+
383402
type imageConfig struct {
384403
config image.Config
385404
configInit sync.Once

‎resources/images/imagetesting/testing.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func RunGolden(opts GoldenImageTestOpts) *hugolib.IntegrationTestBuilder {
125125
shouldSkip := func(d fs.DirEntry) bool {
126126
if runtime.GOARCH == "arm64" {
127127
// TODO(bep) figure out why this fails on arm64. I have inspected the images, and they look identical.
128-
if d.Name() == "giphy_hu_e4a5984f8835d617.webp" {
128+
if d.Name() == "giphy_hu_bb052284cc220165.webp" {
129129
c.Logf("skipping %s on %s", d.Name(), runtime.GOARCH)
130130
return true
131131
}

resources/images/testdata/images_golden/webp/animation/giphy_hu_e4a5984f8835d617.webp renamed to resources/images/testdata/images_golden/webp/animation/giphy_hu_bb052284cc220165.webp

File renamed without changes.

0 commit comments

Comments
 (0)