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.

29 lines
723 B

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