|
|
@ -16,6 +16,15 @@ func Resized(ext string, data []byte, width, height int) (resized []byte, w int, |
|
|
return data, 0, 0 |
|
|
return data, 0, 0 |
|
|
} |
|
|
} |
|
|
srcImage, _, err := image.Decode(bytes.NewReader(data)) |
|
|
srcImage, _, err := image.Decode(bytes.NewReader(data)) |
|
|
|
|
|
|
|
|
|
|
|
dx := srcImage.Bounds().Dx() |
|
|
|
|
|
dy := srcImage.Bounds().Dy() |
|
|
|
|
|
if width/height > dx/dy { //定高
|
|
|
|
|
|
width = height * dx / dy |
|
|
|
|
|
} else if width/height < dx/dy { //定宽
|
|
|
|
|
|
height = width * dy / dx |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if err == nil { |
|
|
if err == nil { |
|
|
bounds := srcImage.Bounds() |
|
|
bounds := srcImage.Bounds() |
|
|
var dstImage *image.NRGBA |
|
|
var dstImage *image.NRGBA |
|
|
|