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