|
@@ -5,11 +5,28 @@ import (
|
|
|
"image"
|
|
|
"image/png"
|
|
|
"log"
|
|
|
+ "mime/multipart"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
+var (
|
|
|
+ imgExtMap = map[string]string{
|
|
|
+ ".jpg": "image/jpeg",
|
|
|
+ ".jpeg": "image/jpeg",
|
|
|
+ ".png": "image/png",
|
|
|
+ }
|
|
|
+)
|
|
|
+
|
|
|
+func CheckImageFormat(fileName string, file multipart.File, header *multipart.FileHeader) bool {
|
|
|
+ ext := strings.ToLower(filepath.Ext(fileName))
|
|
|
+ contentType := header.Header.Get("Content-Type")
|
|
|
+ if imgExtMap[ext] == contentType {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|
|
|
func ImageResize(imageSrc string, maxDimension int) (string, error) {
|
|
|
file, err := os.Open(imageSrc)
|
|
|
if err != nil {
|