preprocess.go 650 B

123456789101112131415161718192021222324252627
  1. package images
  2. import (
  3. "path/filepath"
  4. "strings"
  5. )
  6. /*
  7. * Preprocess image files on client side.
  8. * 1. possibly adjust the orientation
  9. * 2. resize the image to a width or height limit
  10. * 3. remove the exif data
  11. * Call this function on any file uploaded to SeaweedFS
  12. *
  13. */
  14. func MaybePreprocessImage(filename string, data []byte, width, height int) (resized []byte, w int, h int) {
  15. ext := filepath.Ext(filename)
  16. ext = strings.ToLower(ext)
  17. switch ext {
  18. case ".png", ".gif":
  19. return Resized(ext, data, width, height, "")
  20. case ".jpg", ".jpeg":
  21. data = FixJpgOrientation(data)
  22. return Resized(ext, data, width, height, "")
  23. }
  24. return data, 0, 0
  25. }