2014-07-05 01:03:48 +00:00
|
|
|
package images
|
|
|
|
|
|
|
|
import (
|
|
|
|
"path/filepath"
|
2014-07-06 01:01:17 +00:00
|
|
|
"strings"
|
2014-07-05 01:03:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2015-04-16 21:11:25 +00:00
|
|
|
* Call this function on any file uploaded to SeaweedFS
|
2014-07-06 01:01:17 +00:00
|
|
|
*
|
|
|
|
*/
|
2014-07-05 07:43:41 +00:00
|
|
|
func MaybePreprocessImage(filename string, data []byte, width, height int) (resized []byte, w int, h int) {
|
2014-07-05 01:03:48 +00:00
|
|
|
ext := filepath.Ext(filename)
|
2014-07-06 01:01:17 +00:00
|
|
|
ext = strings.ToLower(ext)
|
2014-07-05 01:03:48 +00:00
|
|
|
switch ext {
|
|
|
|
case ".png", ".gif":
|
|
|
|
return Resized(ext, data, width, height)
|
|
|
|
case ".jpg", ".jpeg":
|
2014-07-06 01:01:17 +00:00
|
|
|
data = FixJpgOrientation(data)
|
2014-07-05 01:03:48 +00:00
|
|
|
return Resized(ext, data, width, height)
|
|
|
|
}
|
2014-07-05 07:43:41 +00:00
|
|
|
return data, 0, 0
|
2014-07-05 01:03:48 +00:00
|
|
|
}
|