summaryrefslogtreecommitdiffstats
path: root/app/file.go
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2017-05-24 10:52:05 -0400
committerCorey Hulen <corey@hulen.com>2017-05-24 07:52:05 -0700
commit7ac8eaba925cb9f3d02bc93717cb3c573fd26ec2 (patch)
tree23024e2a10a2989d6cf87f3496a91ceccfe45a0b /app/file.go
parentb84891f654583f5ded287e1f5aa5de3c32be5044 (diff)
downloadchat-7ac8eaba925cb9f3d02bc93717cb3c573fd26ec2.tar.gz
chat-7ac8eaba925cb9f3d02bc93717cb3c573fd26ec2.tar.bz2
chat-7ac8eaba925cb9f3d02bc93717cb3c573fd26ec2.zip
PLT-6534 Rotated uploaded profile pictures to be upright (#6482)
Diffstat (limited to 'app/file.go')
-rw-r--r--app/file.go29
1 files changed, 17 insertions, 12 deletions
diff --git a/app/file.go b/app/file.go
index ad58de623..3b7a6860c 100644
--- a/app/file.go
+++ b/app/file.go
@@ -495,30 +495,35 @@ func prepareImage(fileData []byte) (*image.Image, int, int) {
}
// Flip the image to be upright
- orientation, _ := getImageOrientation(fileData)
+ orientation, _ := getImageOrientation(bytes.NewReader(fileData))
+ img = makeImageUpright(img, orientation)
+ return &img, width, height
+}
+
+func makeImageUpright(img image.Image, orientation int) image.Image {
switch orientation {
case UprightMirrored:
- img = imaging.FlipH(img)
+ return imaging.FlipH(img)
case UpsideDown:
- img = imaging.Rotate180(img)
+ return imaging.Rotate180(img)
case UpsideDownMirrored:
- img = imaging.FlipV(img)
+ return imaging.FlipV(img)
case RotatedCWMirrored:
- img = imaging.Transpose(img)
+ return imaging.Transpose(img)
case RotatedCCW:
- img = imaging.Rotate270(img)
+ return imaging.Rotate270(img)
case RotatedCCWMirrored:
- img = imaging.Transverse(img)
+ return imaging.Transverse(img)
case RotatedCW:
- img = imaging.Rotate90(img)
+ return imaging.Rotate90(img)
+ default:
+ return img
}
-
- return &img, width, height
}
-func getImageOrientation(imageData []byte) (int, error) {
- if exifData, err := exif.Decode(bytes.NewReader(imageData)); err != nil {
+func getImageOrientation(input io.Reader) (int, error) {
+ if exifData, err := exif.Decode(input); err != nil {
return Upright, err
} else {
if tag, err := exifData.Get("Orientation"); err != nil {