prevent images that have a small resolution from being made larger by the size specified
parent
6294e758e2
commit
05d64322dc
|
@ -74,6 +74,22 @@ func SaveImage(fileHeader *multipart.FileHeader, userId string, imagePath string
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prevent images that have a small resolution from being made larger by the size specified
|
||||||
|
size, err := bimg.NewImage(fileData).Size()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
logrus.Errorln("Failed to get image size, err:", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if size.Width < imageWidth {
|
||||||
|
imageWidth = size.Width
|
||||||
|
}
|
||||||
|
|
||||||
|
if size.Height < imageHeight {
|
||||||
|
imageHeight = size.Height
|
||||||
|
}
|
||||||
|
|
||||||
newImage, err := bimg.NewImage(fileData).Process(bimg.Options{
|
newImage, err := bimg.NewImage(fileData).Process(bimg.Options{
|
||||||
Width: imageWidth,
|
Width: imageWidth,
|
||||||
Height: imageHeight,
|
Height: imageHeight,
|
||||||
|
|
Loading…
Reference in New Issue