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
This commit is contained in:
Adrian Shum 2022-10-08 11:55:31 +08:00 committed by GitHub
parent 466ff3ec35
commit 145b4ce8a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 11 additions and 11 deletions

2
go.mod
View file

@ -3,7 +3,7 @@ module github.com/cshum/imagorvideo
go 1.18
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/stretchr/testify v1.8.0
go.uber.org/zap v1.23.0

4
go.sum
View file

@ -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-20211001041855-01bcc9b48dfe/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.7/go.mod h1:7DEd2qtXj469uYoAj5SskR7GZKzwFowIhqYw/x3tlM4=
github.com/cshum/imagor v1.1.8 h1:b+9uwLDmVXaZCH8sfdhP3cjfUUDR22oYRYeib80VZdU=
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.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

View file

@ -131,11 +131,11 @@ func (p *Processor) Process(ctx context.Context, in *imagor.Blob, params imagorp
}
switch meta.Orientation {
case 3:
filters = append(filters, imagorpath.Filter{Name: "rotate", Args: "180"})
filters = append(filters, imagorpath.Filter{Name: "orient", Args: "180"})
case 6:
filters = append(filters, imagorpath.Filter{Name: "rotate", Args: "270"})
filters = append(filters, imagorpath.Filter{Name: "orient", Args: "270"})
case 8:
filters = append(filters, imagorpath.Filter{Name: "rotate", Args: "90"})
filters = append(filters, imagorpath.Filter{Name: "orient", Args: "90"})
}
buf, err := av.Export()
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)
if len(filters) > 0 {
params.Filters = append(filters, params.Filters...)
params.Filters = append(params.Filters, filters...)
params.Path = imagorpath.GeneratePath(params)
}
err = imagor.ErrForward{Params: params}

View file

@ -43,10 +43,10 @@ func TestProcessor(t *testing.T) {
doGoldenTests(t, filepath.Join(testDataDir, "golden/result"), []test{
{name: "mkv", path: "fit-in/100x100/everybody-betray-me.mkv"},
{name: "mkv meta", path: "meta/everybody-betray-me.mkv"},
{name: "mp4", path: "fit-in/100x100/schizo_0.mp4"},
{name: "mp4 90", path: "fit-in/100x100/schizo_90.mp4"},
{name: "mp4 180", path: "fit-in/100x100/schizo_180.mp4"},
{name: "mp4 270", path: "fit-in/100x100/schizo_270.mp4"},
{name: "mp4", path: "200x100/schizo_0.mp4"},
{name: "mp4 orient 90", path: "220x100/schizo_90.mp4"},
{name: "mp4 orient 180", path: "200x100/schizo_180.mp4"},
{name: "mp4 orient 270", path: "200x100/schizo_270.mp4"},
{name: "image", path: "fit-in/100x100/demo.png"},
{name: "corrupted", path: "fit-in/100x100/corrupt/everybody-betray-me.mkv", expectCode: 406},
}, WithDebug(true), WithLogger(zap.NewExample()))

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB