mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 22:21:07 +03:00
resources/image: Fix fill with smartcrop sometimes returning 0 bytes images
Fixes #7955
This commit is contained in:
parent
8eafe0845d
commit
5af045ebab
3 changed files with 113 additions and 31 deletions
|
@ -175,36 +175,6 @@ func TestImageTransformFormat(t *testing.T) {
|
|||
assertFileCache(c, fileCache, path.Base(imageGif.RelPermalink()), 225, 141)
|
||||
}
|
||||
|
||||
// https://github.com/gohugoio/hugo/issues/4261
|
||||
func TestImageTransformLongFilename(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
image := fetchImage(c, "1234567890qwertyuiopasdfghjklzxcvbnm5to6eeeeee7via8eleph.jpg")
|
||||
c.Assert(image, qt.Not(qt.IsNil))
|
||||
|
||||
resized, err := image.Resize("200x")
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(resized, qt.Not(qt.IsNil))
|
||||
c.Assert(resized.Width(), qt.Equals, 200)
|
||||
c.Assert(resized.RelPermalink(), qt.Equals, "/a/_hu59e56ffff1bc1d8d122b1403d34e039f_90587_65b757a6e14debeae720fe8831f0a9bc.jpg")
|
||||
resized, err = resized.Resize("100x")
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(resized, qt.Not(qt.IsNil))
|
||||
c.Assert(resized.Width(), qt.Equals, 100)
|
||||
c.Assert(resized.RelPermalink(), qt.Equals, "/a/_hu59e56ffff1bc1d8d122b1403d34e039f_90587_c876768085288f41211f768147ba2647.jpg")
|
||||
}
|
||||
|
||||
// Issue 6137
|
||||
func TestImageTransformUppercaseExt(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
image := fetchImage(c, "sunrise.JPG")
|
||||
|
||||
resized, err := image.Resize("200x")
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(resized, qt.Not(qt.IsNil))
|
||||
c.Assert(resized.Width(), qt.Equals, 200)
|
||||
}
|
||||
|
||||
// https://github.com/gohugoio/hugo/issues/5730
|
||||
func TestImagePermalinkPublishOrder(t *testing.T) {
|
||||
for _, checkOriginalFirst := range []bool{true, false} {
|
||||
|
@ -250,6 +220,70 @@ func TestImagePermalinkPublishOrder(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestImageBugs(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
// Issue #4261
|
||||
c.Run("Transform long filename", func(c *qt.C) {
|
||||
image := fetchImage(c, "1234567890qwertyuiopasdfghjklzxcvbnm5to6eeeeee7via8eleph.jpg")
|
||||
c.Assert(image, qt.Not(qt.IsNil))
|
||||
|
||||
resized, err := image.Resize("200x")
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(resized, qt.Not(qt.IsNil))
|
||||
c.Assert(resized.Width(), qt.Equals, 200)
|
||||
c.Assert(resized.RelPermalink(), qt.Equals, "/a/_hu59e56ffff1bc1d8d122b1403d34e039f_90587_65b757a6e14debeae720fe8831f0a9bc.jpg")
|
||||
resized, err = resized.Resize("100x")
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(resized, qt.Not(qt.IsNil))
|
||||
c.Assert(resized.Width(), qt.Equals, 100)
|
||||
c.Assert(resized.RelPermalink(), qt.Equals, "/a/_hu59e56ffff1bc1d8d122b1403d34e039f_90587_c876768085288f41211f768147ba2647.jpg")
|
||||
|
||||
})
|
||||
|
||||
// Issue #6137
|
||||
c.Run("Transform upper case extension", func(c *qt.C) {
|
||||
image := fetchImage(c, "sunrise.JPG")
|
||||
|
||||
resized, err := image.Resize("200x")
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(resized, qt.Not(qt.IsNil))
|
||||
c.Assert(resized.Width(), qt.Equals, 200)
|
||||
|
||||
})
|
||||
|
||||
// Issue #7955
|
||||
c.Run("Fill with smartcrop", func(c *qt.C) {
|
||||
sunset := fetchImage(c, "sunset.jpg")
|
||||
|
||||
for _, test := range []struct {
|
||||
originalDimensions string
|
||||
targetWH int
|
||||
}{
|
||||
{"408x403", 400},
|
||||
{"425x403", 400},
|
||||
{"459x429", 400},
|
||||
{"476x442", 400},
|
||||
{"544x403", 400},
|
||||
{"476x468", 400},
|
||||
{"578x585", 550},
|
||||
{"578x598", 550},
|
||||
} {
|
||||
c.Run(test.originalDimensions, func(c *qt.C) {
|
||||
image, err := sunset.Resize(test.originalDimensions)
|
||||
c.Assert(err, qt.IsNil)
|
||||
resized, err := image.Fill(fmt.Sprintf("%dx%d smart", test.targetWH, test.targetWH))
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(resized, qt.Not(qt.IsNil))
|
||||
c.Assert(resized.Width(), qt.Equals, test.targetWH)
|
||||
c.Assert(resized.Height(), qt.Equals, test.targetWH)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
func TestImageTransformConcurrent(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue