fix(imagorvideo): fix image orientation from video exif (#18)
* fix(imagorvideo): orient image before resize * test: update golden files * fix(imagorvideo): orient image before resize * test: update golden files
2
go.mod
|
|
@ -3,7 +3,7 @@ module github.com/cshum/imagorvideo
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/cshum/imagor v1.1.7
|
github.com/cshum/imagor v1.1.8
|
||||||
github.com/gabriel-vasile/mimetype v1.4.1
|
github.com/gabriel-vasile/mimetype v1.4.1
|
||||||
github.com/stretchr/testify v1.8.0
|
github.com/stretchr/testify v1.8.0
|
||||||
go.uber.org/zap v1.23.0
|
go.uber.org/zap v1.23.0
|
||||||
|
|
|
||||||
4
go.sum
|
|
@ -85,8 +85,8 @@ github.com/cncf/xds/go v0.0.0-20210805033703-aa0b78936158/go.mod h1:eXthEFrGJvWH
|
||||||
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
github.com/cncf/xds/go v0.0.0-20210922020428-25de7278fc84/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||||
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
github.com/cncf/xds/go v0.0.0-20211001041855-01bcc9b48dfe/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||||
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
github.com/cncf/xds/go v0.0.0-20211011173535-cb28da3451f1/go.mod h1:eXthEFrGJvWHgFFCl3hGmgk+/aYT6PnTQLykKQRLhEs=
|
||||||
github.com/cshum/imagor v1.1.7 h1:+eUUJFeBdbmeF2zAaSETt/+vjpeQ+pM8EitO9ov2rEc=
|
github.com/cshum/imagor v1.1.8 h1:b+9uwLDmVXaZCH8sfdhP3cjfUUDR22oYRYeib80VZdU=
|
||||||
github.com/cshum/imagor v1.1.7/go.mod h1:7DEd2qtXj469uYoAj5SskR7GZKzwFowIhqYw/x3tlM4=
|
github.com/cshum/imagor v1.1.8/go.mod h1:7DEd2qtXj469uYoAj5SskR7GZKzwFowIhqYw/x3tlM4=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
|
|
||||||
|
|
@ -131,11 +131,11 @@ func (p *Processor) Process(ctx context.Context, in *imagor.Blob, params imagorp
|
||||||
}
|
}
|
||||||
switch meta.Orientation {
|
switch meta.Orientation {
|
||||||
case 3:
|
case 3:
|
||||||
filters = append(filters, imagorpath.Filter{Name: "rotate", Args: "180"})
|
filters = append(filters, imagorpath.Filter{Name: "orient", Args: "180"})
|
||||||
case 6:
|
case 6:
|
||||||
filters = append(filters, imagorpath.Filter{Name: "rotate", Args: "270"})
|
filters = append(filters, imagorpath.Filter{Name: "orient", Args: "270"})
|
||||||
case 8:
|
case 8:
|
||||||
filters = append(filters, imagorpath.Filter{Name: "rotate", Args: "90"})
|
filters = append(filters, imagorpath.Filter{Name: "orient", Args: "90"})
|
||||||
}
|
}
|
||||||
buf, err := av.Export()
|
buf, err := av.Export()
|
||||||
if err != nil || len(buf) == 0 {
|
if err != nil || len(buf) == 0 {
|
||||||
|
|
@ -151,7 +151,7 @@ func (p *Processor) Process(ctx context.Context, in *imagor.Blob, params imagorp
|
||||||
out = imagor.NewBlobFromMemory(buf, meta.Width, meta.Height, bands)
|
out = imagor.NewBlobFromMemory(buf, meta.Width, meta.Height, bands)
|
||||||
|
|
||||||
if len(filters) > 0 {
|
if len(filters) > 0 {
|
||||||
params.Filters = append(filters, params.Filters...)
|
params.Filters = append(params.Filters, filters...)
|
||||||
params.Path = imagorpath.GeneratePath(params)
|
params.Path = imagorpath.GeneratePath(params)
|
||||||
}
|
}
|
||||||
err = imagor.ErrForward{Params: params}
|
err = imagor.ErrForward{Params: params}
|
||||||
|
|
|
||||||
|
|
@ -43,10 +43,10 @@ func TestProcessor(t *testing.T) {
|
||||||
doGoldenTests(t, filepath.Join(testDataDir, "golden/result"), []test{
|
doGoldenTests(t, filepath.Join(testDataDir, "golden/result"), []test{
|
||||||
{name: "mkv", path: "fit-in/100x100/everybody-betray-me.mkv"},
|
{name: "mkv", path: "fit-in/100x100/everybody-betray-me.mkv"},
|
||||||
{name: "mkv meta", path: "meta/everybody-betray-me.mkv"},
|
{name: "mkv meta", path: "meta/everybody-betray-me.mkv"},
|
||||||
{name: "mp4", path: "fit-in/100x100/schizo_0.mp4"},
|
{name: "mp4", path: "200x100/schizo_0.mp4"},
|
||||||
{name: "mp4 90", path: "fit-in/100x100/schizo_90.mp4"},
|
{name: "mp4 orient 90", path: "220x100/schizo_90.mp4"},
|
||||||
{name: "mp4 180", path: "fit-in/100x100/schizo_180.mp4"},
|
{name: "mp4 orient 180", path: "200x100/schizo_180.mp4"},
|
||||||
{name: "mp4 270", path: "fit-in/100x100/schizo_270.mp4"},
|
{name: "mp4 orient 270", path: "200x100/schizo_270.mp4"},
|
||||||
{name: "image", path: "fit-in/100x100/demo.png"},
|
{name: "image", path: "fit-in/100x100/demo.png"},
|
||||||
{name: "corrupted", path: "fit-in/100x100/corrupt/everybody-betray-me.mkv", expectCode: 406},
|
{name: "corrupted", path: "fit-in/100x100/corrupt/everybody-betray-me.mkv", expectCode: 406},
|
||||||
}, WithDebug(true), WithLogger(zap.NewExample()))
|
}, WithDebug(true), WithLogger(zap.NewExample()))
|
||||||
|
|
|
||||||
BIN
testdata/golden/result/200x100/schizo_0.mp4
vendored
Normal file
|
After Width: | Height: | Size: 7.7 KiB |
BIN
testdata/golden/result/200x100/schizo_180.mp4
vendored
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
testdata/golden/result/200x100/schizo_270.mp4
vendored
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
testdata/golden/result/220x100/schizo_90.mp4
vendored
Normal file
|
After Width: | Height: | Size: 8.1 KiB |
BIN
testdata/golden/result/fit-in/100x100/schizo_0.mp4
vendored
|
Before Width: | Height: | Size: 3.8 KiB |
BIN
testdata/golden/result/fit-in/100x100/schizo_180.mp4
vendored
|
Before Width: | Height: | Size: 3.8 KiB |
BIN
testdata/golden/result/fit-in/100x100/schizo_270.mp4
vendored
|
Before Width: | Height: | Size: 3.8 KiB |
BIN
testdata/golden/result/fit-in/100x100/schizo_90.mp4
vendored
|
Before Width: | Height: | Size: 3.8 KiB |