summaryrefslogtreecommitdiffstats
path: root/api/file.go
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-09-18 18:00:09 -0400
committerhmhealey <harrisonmhealey@gmail.com>2015-09-21 09:17:23 -0400
commit4b177a6ed5c8e72dff483b4e00738f65724f7d81 (patch)
tree262f32f4d9099ec3dd344bd9eefefdac55bcfb05 /api/file.go
parent48110020afacbeb71d6c9b26a08a92ca1b743c6a (diff)
downloadchat-4b177a6ed5c8e72dff483b4e00738f65724f7d81.tar.gz
chat-4b177a6ed5c8e72dff483b4e00738f65724f7d81.tar.bz2
chat-4b177a6ed5c8e72dff483b4e00738f65724f7d81.zip
Added constants for EXIF orientations
Diffstat (limited to 'api/file.go')
-rw-r--r--api/file.go40
1 files changed, 31 insertions, 9 deletions
diff --git a/api/file.go b/api/file.go
index b162065b5..467bf5338 100644
--- a/api/file.go
+++ b/api/file.go
@@ -33,6 +33,27 @@ import (
"time"
)
+const (
+ /*
+ EXIF Image Orientations
+ 1 2 3 4 5 6 7 8
+
+ 888888 888888 88 88 8888888888 88 88 8888888888
+ 88 88 88 88 88 88 88 88 88 88 88 88
+ 8888 8888 8888 8888 88 8888888888 8888888888 88
+ 88 88 88 88
+ 88 88 888888 888888
+ */
+ Upright = 1
+ UprightMirrored = 2
+ UpsideDown = 3
+ UpsideDownMirrored = 4
+ RotatedCWMirrored = 5
+ RotatedCCW = 6
+ RotatedCCWMirrored = 7
+ RotatedCW = 8
+)
+
var fileInfoCache *utils.Cache = utils.NewLru(1000)
func InitFile(r *mux.Router) {
@@ -154,9 +175,10 @@ func fireAndForgetHandleImages(filenames []string, fileData [][]byte, teamId, ch
// Create a temporary image that will be manipulated and then used to make the thumbnail and preview image
var temp *image.RGBA
- if orientation >= 1 && orientation <= 4 {
+ switch orientation {
+ case Upright, UprightMirrored, UpsideDown, UpsideDownMirrored:
temp = image.NewRGBA(img.Bounds())
- } else {
+ case RotatedCCW, RotatedCCWMirrored, RotatedCW, RotatedCWMirrored:
bounds := img.Bounds()
temp = image.NewRGBA(image.Rect(bounds.Min.Y, bounds.Min.X, bounds.Max.Y, bounds.Max.X))
@@ -168,25 +190,25 @@ func fireAndForgetHandleImages(filenames []string, fileData [][]byte, teamId, ch
// Copy the original image onto the temporary one while rotating it as necessary
switch orientation {
- case 3, 4:
+ case UpsideDown, UpsideDownMirrored:
// rotate 180 degrees
err := graphics.Rotate(temp, img, &graphics.RotateOptions{Angle: math.Pi})
if err != nil {
l4g.Error("Unable to rotate image")
}
- case 5, 8:
+ case RotatedCW, RotatedCWMirrored:
// rotate 90 degrees CCW
graphics.Rotate(temp, img, &graphics.RotateOptions{Angle: 3 * math.Pi / 2})
if err != nil {
l4g.Error("Unable to rotate image")
}
- case 6, 7:
+ case RotatedCCW, RotatedCCWMirrored:
// rotate 90 degrees CW
graphics.Rotate(temp, img, &graphics.RotateOptions{Angle: math.Pi / 2})
if err != nil {
l4g.Error("Unable to rotate image")
}
- case 1, 2:
+ case Upright, UprightMirrored:
draw.Draw(temp, temp.Bounds(), img, img.Bounds().Min, draw.Over)
}
@@ -250,14 +272,14 @@ func fireAndForgetHandleImages(filenames []string, fileData [][]byte, teamId, ch
func getImageOrientation(imageData []byte) (int, error) {
if exifData, err := exif.Decode(bytes.NewReader(imageData)); err != nil {
- return 1, err
+ return Upright, err
} else {
if tag, err := exifData.Get("Orientation"); err != nil {
- return 1, err
+ return Upright, err
} else {
orientation, err := tag.Int(0)
if err != nil {
- return 1, err
+ return Upright, err
} else {
return orientation, nil
}