use different library to resize map
This commit is contained in:
parent
84d1514456
commit
41100e1156
|
@ -7,8 +7,6 @@ import (
|
|||
"image/png"
|
||||
"io"
|
||||
|
||||
"github.com/nfnt/resize"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tribalwarshelp/shared/models"
|
||||
)
|
||||
|
@ -136,8 +134,8 @@ func Generate(cfg Config) error {
|
|||
|
||||
var resizedImg image.Image = img
|
||||
if cfg.Scale != 1 {
|
||||
width := uint(float32(cfg.MapSize) * cfg.Scale)
|
||||
resizedImg = resize.Resize(width, width, img, resize.Lanczos3)
|
||||
width := int(float32(cfg.MapSize) * cfg.Scale)
|
||||
resizedImg = scale(img, image.Rect(0, 0, width, width))
|
||||
}
|
||||
|
||||
b := resizedImg.Bounds()
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"image"
|
||||
"image/color"
|
||||
|
||||
"golang.org/x/image/draw"
|
||||
"golang.org/x/image/font"
|
||||
"golang.org/x/image/font/basicfont"
|
||||
"golang.org/x/image/math/fixed"
|
||||
|
@ -62,3 +63,9 @@ func drawText(img *image.RGBA, x, y int, col color.RGBA, text string) {
|
|||
}
|
||||
d.DrawString(text)
|
||||
}
|
||||
|
||||
func scale(src image.Image, rect image.Rectangle) image.Image {
|
||||
dst := image.NewRGBA(rect)
|
||||
draw.NearestNeighbor.Scale(dst, rect, src, src.Bounds(), draw.Over, nil)
|
||||
return dst
|
||||
}
|
||||
|
|
1
go.mod
1
go.mod
|
@ -3,7 +3,6 @@ module github.com/tribalwarshelp/map-generator
|
|||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/tribalwarshelp/shared v0.0.0-20200622084436-3a768c8bf574
|
||||
golang.org/x/image v0.0.0-20200618115811-c13761719519
|
||||
|
|
2
go.sum
2
go.sum
|
@ -1,5 +1,3 @@
|
|||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/tribalwarshelp/shared v0.0.0-20200622084436-3a768c8bf574 h1:y2EoH6zRK9Uc0AeswnJRYUUIQYcSLZB5VDFuxPCKxNM=
|
||||
|
|
Reference in New Issue