aboutsummaryrefslogtreecommitdiff
path: root/go/images/preprocess.go
diff options
context:
space:
mode:
Diffstat (limited to 'go/images/preprocess.go')
-rw-r--r--go/images/preprocess.go25
1 files changed, 25 insertions, 0 deletions
diff --git a/go/images/preprocess.go b/go/images/preprocess.go
new file mode 100644
index 000000000..b5907b1b8
--- /dev/null
+++ b/go/images/preprocess.go
@@ -0,0 +1,25 @@
+package images
+
+import (
+ "path/filepath"
+)
+
+/*
+* Preprocess image files on client side.
+* 1. possibly adjust the orientation
+* 2. resize the image to a width or height limit
+* 3. remove the exif data
+* Call this function on any file uploaded to weedfs
+*
+*/
+func MaybePreprocessImage(filename string, data []byte, width, height int) (resized []byte) {
+ ext := filepath.Ext(filename)
+ switch ext {
+ case ".png", ".gif":
+ return Resized(ext, data, width, height)
+ case ".jpg", ".jpeg":
+ data = FixJpgOrientation(data)
+ return Resized(ext, data, width, height)
+ }
+ return data
+}