You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
650 B

  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. }