mirror of
https://github.com/gohugoio/hugo.git
synced 2025-04-27 22:21:07 +03:00
resources: Cache Exif data to disk
```bash name old time/op new time/op delta ImageExif/Cold_cache-4 312µs ±28% 355µs ± 7% ~ (p=0.343 n=4+4) ImageExif/Cold_cache,_10-4 479µs ± 6% 546µs ± 0% +13.91% (p=0.029 n=4+4) ImageExif/Warm_cache-4 272µs ± 1% 81µs ± 5% -70.30% (p=0.029 n=4+4) name old alloc/op new alloc/op delta ImageExif/Cold_cache-4 151kB ± 0% 161kB ± 0% +6.46% (p=0.029 n=4+4) ImageExif/Cold_cache,_10-4 179kB ± 0% 189kB ± 0% +5.49% (p=0.029 n=4+4) ImageExif/Warm_cache-4 151kB ± 0% 13kB ± 0% -91.52% (p=0.029 n=4+4) name old allocs/op new allocs/op delta ImageExif/Cold_cache-4 1.03k ± 0% 1.21k ± 0% +17.78% (p=0.029 n=4+4) ImageExif/Cold_cache,_10-4 1.65k ± 0% 1.83k ± 0% +11.09% (p=0.029 n=4+4) ImageExif/Warm_cache-4 1.03k ± 0% 0.28k ± 0% -72.40% (p=0.029 n=4+4) ``` Fixes #6291
This commit is contained in:
parent
de9cbf6195
commit
ce47c21a29
7 changed files with 172 additions and 41 deletions
|
@ -15,6 +15,7 @@ package resources
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -22,6 +23,7 @@ import (
|
|||
"strconv"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/afero"
|
||||
|
||||
|
@ -50,6 +52,14 @@ var eq = qt.CmpEquals(
|
|||
cmp.Comparer(func(m1, m2 media.Type) bool {
|
||||
return m1.Type() == m2.Type()
|
||||
}),
|
||||
cmp.Comparer(
|
||||
func(v1, v2 *big.Rat) bool {
|
||||
return v1.RatString() == v2.RatString()
|
||||
},
|
||||
),
|
||||
cmp.Comparer(func(v1, v2 time.Time) bool {
|
||||
return v1.Unix() == v2.Unix()
|
||||
}),
|
||||
)
|
||||
|
||||
func TestImageTransformBasic(t *testing.T) {
|
||||
|
@ -336,27 +346,35 @@ func TestSVGImageContent(t *testing.T) {
|
|||
|
||||
func TestImageExif(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
image := fetchImage(c, "sunset.jpg")
|
||||
fs := afero.NewMemMapFs()
|
||||
spec := newTestResourceSpec(specDescriptor{fs: fs, c: c})
|
||||
image := fetchResourceForSpec(spec, c, "sunset.jpg").(resource.Image)
|
||||
|
||||
x, err := image.Exif()
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(x, qt.Not(qt.IsNil))
|
||||
getAndCheckExif := func(c *qt.C, image resource.Image) {
|
||||
x, err := image.Exif()
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(x, qt.Not(qt.IsNil))
|
||||
|
||||
c.Assert(x.Date.Format("2006-01-02"), qt.Equals, "2017-10-27")
|
||||
c.Assert(x.Date.Format("2006-01-02"), qt.Equals, "2017-10-27")
|
||||
|
||||
// Malaga: https://goo.gl/taazZy
|
||||
c.Assert(x.Lat, qt.Equals, float64(36.59744166666667))
|
||||
c.Assert(x.Long, qt.Equals, float64(-4.50846))
|
||||
// Malaga: https://goo.gl/taazZy
|
||||
c.Assert(x.Lat, qt.Equals, float64(36.59744166666667))
|
||||
c.Assert(x.Long, qt.Equals, float64(-4.50846))
|
||||
|
||||
v, found := x.Values["LensModel"]
|
||||
c.Assert(found, qt.Equals, true)
|
||||
lensModel, ok := v.(string)
|
||||
c.Assert(ok, qt.Equals, true)
|
||||
c.Assert(lensModel, qt.Equals, "smc PENTAX-DA* 16-50mm F2.8 ED AL [IF] SDM")
|
||||
v, found := x.Tags["LensModel"]
|
||||
c.Assert(found, qt.Equals, true)
|
||||
lensModel, ok := v.(string)
|
||||
c.Assert(ok, qt.Equals, true)
|
||||
c.Assert(lensModel, qt.Equals, "smc PENTAX-DA* 16-50mm F2.8 ED AL [IF] SDM")
|
||||
resized, _ := image.Resize("300x200")
|
||||
x2, _ := resized.Exif()
|
||||
c.Assert(x2, eq, x)
|
||||
}
|
||||
|
||||
resized, _ := image.Resize("300x200")
|
||||
x2, _ := resized.Exif()
|
||||
c.Assert(x2, qt.Equals, x)
|
||||
getAndCheckExif(c, image)
|
||||
image = fetchResourceForSpec(spec, c, "sunset.jpg").(resource.Image)
|
||||
// This will read from file cache.
|
||||
getAndCheckExif(c, image)
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue