2014-07-05 09:03:48 +08:00
|
|
|
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
|
|
|
|
*
|
|
|
|
*/
|
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)
|
|
|
|
switch ext {
|
|
|
|
case ".png", ".gif":
|
|
|
|
return Resized(ext, data, width, height)
|
|
|
|
case ".jpg", ".jpeg":
|
|
|
|
data = FixJpgOrientation(data)
|
|
|
|
return Resized(ext, data, width, height)
|
|
|
|
}
|
2014-07-05 15:43:41 +08:00
|
|
|
return data, 0, 0
|
2014-07-05 09:03:48 +08:00
|
|
|
}
|