diff options
author | Rob Jackson <rob@rjackson.me> | 2018-07-31 14:31:35 +0300 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2018-07-31 14:31:35 +0300 |
commit | b718d743b7a2eff3bea74ced57147825294a629f (patch) | |
tree | f75ae7ee74522d0ac1e5632207454b33c26fa10e /resource | |
parent | 0ba19c57f180c33b41c64335ea1d1c89335d34c0 (diff) |
Fix file paths for uncached transformed images
This commit also fixes an existing test to work according to the correct logic. The test was written based on erroneous behavior. We resize the image to 300x200px, and are now trying to fit it within a 50px square. The longest edge is 300 pixels, so we need to divide it by 6 (300 / 50 == 6). And then scale the shortest edge with the same proportion (200 / 6 == 33.33).
The original test was transforming the original source image, hence the previous values:
900 x 562
900 / 50 == 18
562 / 18 == 31.22
Fixes #5012
Diffstat (limited to 'resource')
-rw-r--r-- | resource/image_cache.go | 8 | ||||
-rw-r--r-- | resource/image_test.go | 4 |
2 files changed, 7 insertions, 5 deletions
diff --git a/resource/image_cache.go b/resource/image_cache.go index e5149e7a2..fb2996c9d 100644 --- a/resource/image_cache.go +++ b/resource/image_cache.go @@ -100,16 +100,16 @@ func (c *imageCache) getOrCreate( if exists { img = parent.clone() - img.relTargetDirFile.file = relTarget.file - img.sourceFilename = cacheFilename - // We have to look in the resources file system for this. - img.overriddenSourceFs = img.spec.BaseFs.Resources.Fs } else { img, err = create(cacheFilename) if err != nil { return nil, err } } + img.relTargetDirFile.file = relTarget.file + img.sourceFilename = cacheFilename + // We have to look in the resources file system for this. + img.overriddenSourceFs = img.spec.BaseFs.Resources.Fs c.mu.Lock() if img2, found := c.store[key]; found { diff --git a/resource/image_test.go b/resource/image_test.go index f4d91bd99..9379709c4 100644 --- a/resource/image_test.go +++ b/resource/image_test.go @@ -73,6 +73,7 @@ func TestImageTransformBasic(t *testing.T) { assert.NoError(err) assert.True(image != resized) assert.True(image.genericResource != resized.genericResource) + assert.True(image.sourceFilename != resized.sourceFilename) resized0x, err := image.Resize("x200") assert.NoError(err) @@ -100,7 +101,7 @@ func TestImageTransformBasic(t *testing.T) { assert.NoError(err) assert.Equal("/a/sunset_hu59e56ffff1bc1d8d122b1403d34e039f_90587_625708021e2bb281c9f1002f88e4753f.jpg", fitted.RelPermalink()) assert.Equal(50, fitted.Width()) - assert.Equal(31, fitted.Height()) + assert.Equal(33, fitted.Height()) // Check the MD5 key threshold fittedAgain, _ := fitted.Fit("10x20") @@ -128,6 +129,7 @@ func TestImageTransformBasic(t *testing.T) { filledAgain, err := image.Fill("200x100 bottomLeft") assert.NoError(err) assert.True(filled == filledAgain) + assert.True(filled.sourceFilename == filledAgain.sourceFilename) assertFileCache(assert, image.spec.BaseFs.Resources.Fs, filledAgain.RelPermalink(), 200, 100) } |