change image resizing library
This commit is contained in:
parent
41100e1156
commit
cc037d744b
|
@ -4,9 +4,11 @@ import (
|
|||
"fmt"
|
||||
"image"
|
||||
"image/draw"
|
||||
"image/png"
|
||||
"image/jpeg"
|
||||
"io"
|
||||
|
||||
"github.com/disintegration/imaging"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tribalwarshelp/shared/models"
|
||||
)
|
||||
|
@ -135,7 +137,7 @@ func Generate(cfg Config) error {
|
|||
var resizedImg image.Image = img
|
||||
if cfg.Scale != 1 {
|
||||
width := int(float32(cfg.MapSize) * cfg.Scale)
|
||||
resizedImg = scale(img, image.Rect(0, 0, width, width))
|
||||
resizedImg = imaging.Resize(img, width, width, imaging.NearestNeighbor)
|
||||
}
|
||||
|
||||
b := resizedImg.Bounds()
|
||||
|
@ -145,7 +147,9 @@ func Generate(cfg Config) error {
|
|||
Y: cfg.CenterY - imgHalfHeight,
|
||||
}, draw.Src)
|
||||
|
||||
if err := png.Encode(cfg.Destination, centered); err != nil {
|
||||
if err := jpeg.Encode(cfg.Destination, centered, &jpeg.Options{
|
||||
Quality: 80,
|
||||
}); err != nil {
|
||||
return errors.Wrap(err, "map-generator")
|
||||
}
|
||||
return nil
|
||||
|
|
|
@ -5,7 +5,6 @@ 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"
|
||||
|
@ -63,9 +62,3 @@ 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,6 +3,7 @@ module github.com/tribalwarshelp/map-generator
|
|||
go 1.14
|
||||
|
||||
require (
|
||||
github.com/disintegration/imaging v1.6.2
|
||||
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
|
||||
|
|
3
go.sum
3
go.sum
|
@ -1,7 +1,10 @@
|
|||
github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1ei82L+c=
|
||||
github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4=
|
||||
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=
|
||||
github.com/tribalwarshelp/shared v0.0.0-20200622084436-3a768c8bf574/go.mod h1:tf+2yTHasV6jAF3V2deZ9slNoCyBzC0fMdTjI7clf6Y=
|
||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/image v0.0.0-20200618115811-c13761719519 h1:1e2ufUJNM3lCHEY5jIgac/7UTjd6cgJNdatjPdFWf34=
|
||||
golang.org/x/image v0.0.0-20200618115811-c13761719519/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
|
Reference in New Issue