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.

25 lines
581 B

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