2020-09-18 14:43:34 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
|
|
|
"image/draw"
|
|
|
|
"log"
|
2020-09-18 14:51:53 +00:00
|
|
|
|
|
|
|
"github.com/nfnt/resize"
|
|
|
|
"github.com/oliamb/cutter"
|
2020-09-18 14:43:34 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func cropImage(img image.Image) image.Image {
|
|
|
|
var sl int
|
|
|
|
if img.Bounds().Max.X > img.Bounds().Max.Y {
|
|
|
|
sl = img.Bounds().Max.Y
|
|
|
|
} else {
|
|
|
|
sl = img.Bounds().Max.X
|
|
|
|
}
|
|
|
|
|
|
|
|
croppedImg, err := cutter.Crop(img, cutter.Config{
|
|
|
|
Width: sl,
|
|
|
|
Height: sl,
|
|
|
|
Mode: cutter.Centered,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return croppedImg
|
|
|
|
}
|
|
|
|
|
2020-09-18 14:51:53 +00:00
|
|
|
func resizeSquareImage(size uint, img image.Image) image.Image {
|
|
|
|
return resize.Resize(size, 0, img, resize.Bilinear)
|
|
|
|
}
|
|
|
|
|
2020-09-18 14:43:34 +00:00
|
|
|
func circleCropImage(img image.Image, size int) image.Image {
|
|
|
|
dst := image.NewRGBA(image.Rect(0, 0, size, size))
|
|
|
|
draw.DrawMask(
|
|
|
|
dst,
|
|
|
|
dst.Bounds(),
|
|
|
|
img,
|
|
|
|
image.Point{},
|
|
|
|
&circle{
|
|
|
|
image.Point{X: size / 2, Y: size / 2},
|
|
|
|
size / 2,
|
|
|
|
},
|
|
|
|
image.Point{},
|
|
|
|
draw.Over,
|
|
|
|
)
|
|
|
|
return dst
|
|
|
|
}
|