File size: 550 Bytes
ca7217f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package imageutil

import (
	"image"

	"github.com/disintegration/imaging"
)

// Resize provides a simple interface to resize image.
func Resize(src image.Image, width, height int) image.Image {
	switch {
	case width == 0 && height == 0:
		return src /* not modified */
	case width == 0:
		width = int(float64(height) / float64(src.Bounds().Dy()) * float64(src.Bounds().Dx()))
	case height == 0:
		height = int(float64(width) / float64(src.Bounds().Dx()) * float64(src.Bounds().Dy()))
	}
	return imaging.Resize(src, width, height, imaging.Lanczos)
}