Skip to content

Commit

Permalink
Honor exif tag orientation data when resizing images.
Browse files Browse the repository at this point in the history
The golang standard library has an open bug about this, and so we just
fall back on a third party library. Most of these libraries seem to
function in the same way.

https://www.daveperrett.com/articles/2012/07/28/exif-orientation-handling-is-a-ghetto/

golang/go#4341
  • Loading branch information
jlewallen committed Nov 25, 2020
1 parent 8db16e0 commit 5942fbe
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion server/api/utilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"image"
"image/jpeg"

"github.com/disintegration/imageorient"
"github.com/muesli/smartcrop"
"github.com/muesli/smartcrop/nfnt"

Expand All @@ -26,7 +27,7 @@ type ResizedImage struct {
}

func resizeLoadedMedia(ctx context.Context, lm *repositories.LoadedMedia, newWidth, newHeight uint) (resized *ResizedImage, err error) {
original, _, err := image.Decode(lm.Reader)
original, _, err := imageorient.Decode(lm.Reader)
if err != nil {
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ require (
github.com/dgrijalva/jwt-go v0.0.0-20170201225849-2268707a8f08
github.com/dimfeld/httppath v0.0.0-20170720192232-ee938bf73598
github.com/dimfeld/httptreemux v5.0.1+incompatible
github.com/disintegration/gift v1.2.1 // indirect
github.com/disintegration/imageorient v0.0.0-20180920195336-8147d86e83ec
github.com/dropbox/godropbox v0.0.0-20190501155911-5749d3b71cbe // indirect
github.com/fieldkit/app-protocol v0.0.0-20200515173549-e0925480073d
github.com/fieldkit/data-protocol v0.0.0-20200825203301-d452c6499956
Expand Down
6 changes: 6 additions & 0 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ github.com/dimfeld/httptreemux v5.0.1+incompatible h1:Qj3gVcDNoOthBAqftuD596rm4w
github.com/dimfeld/httptreemux v5.0.1+incompatible/go.mod h1:rbUlSV+CCpv/SuqUTP/8Bk2O3LyUV436/yaRGkhP6Z0=
github.com/dimfeld/httptreemux/v5 v5.0.2 h1:q+c+zKVpQocXT2OGa7dsXCX9wdeDq2TO5INqqDfKRLE=
github.com/dimfeld/httptreemux/v5 v5.0.2/go.mod h1:QeEylH57C0v3VO0tkKraVz9oD3Uu93CKPnTLbsidvSw=
github.com/disintegration/gift v1.1.2 h1:9ZyHJr+kPamiH10FX3Pynt1AxFUob812bU9Wt4GMzhs=
github.com/disintegration/gift v1.1.2/go.mod h1:Jh2i7f7Q2BM7Ezno3PhfezbR1xpUg9dUg3/RlKGr4HI=
github.com/disintegration/gift v1.2.1 h1:Y005a1X4Z7Uc+0gLpSAsKhWi4qLtsdEcMIbbdvdZ6pc=
github.com/disintegration/gift v1.2.1/go.mod h1:Jh2i7f7Q2BM7Ezno3PhfezbR1xpUg9dUg3/RlKGr4HI=
github.com/disintegration/imageorient v0.0.0-20180920195336-8147d86e83ec h1:YrB6aVr9touOt75I9O1SiancmR2GMg45U9UYf0gtgWg=
github.com/disintegration/imageorient v0.0.0-20180920195336-8147d86e83ec/go.mod h1:K0KBFIr1gWu/C1Gp10nFAcAE4hsB7JxE6OgLijrJ8Sk=
github.com/docker/distribution v2.7.0+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v1.4.2-0.20200213202729-31a86c4ab209/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
Expand Down

0 comments on commit 5942fbe

Please sign in to comment.