cowboy: stop scaling the base image so much

This commit is contained in:
Chris Sexton 2022-07-22 09:14:00 -04:00
parent 1d30a25277
commit 79cdd0f828
1 changed files with 6 additions and 5 deletions

View File

@ -6,6 +6,7 @@ import (
"image" "image"
"image/draw" "image/draw"
"image/png" "image/png"
"math"
"os" "os"
"path" "path"
@ -54,12 +55,12 @@ func cowboyifyImage(c *config.Config, input image.Image) (image.Image, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
targetW := uint(c.GetInt("cowboy.targetw", 64)) inputW, inputH := float64(input.Bounds().Max.X), float64(input.Bounds().Max.Y)
hatW, hatH := float64(hat.Bounds().Max.X), float64(hat.Bounds().Max.Y) hatW, hatH := float64(hat.Bounds().Max.X), float64(hat.Bounds().Max.Y)
newH := uint(float64(targetW) / hatW * hatH) targetSZ := math.Max(inputW, inputH)
hat = resize.Resize(targetW, newH, hat, resize.MitchellNetravali) dst := image.NewRGBA(image.Rect(0, 0, int(targetSZ), int(targetSZ)))
input = resize.Resize(targetW, targetW, input, resize.MitchellNetravali) newH := uint(targetSZ / hatW * hatH)
dst := image.NewRGBA(image.Rect(0, 0, 64, 64)) hat = resize.Resize(uint(targetSZ), newH, hat, resize.Lanczos3)
draw.Draw(dst, input.Bounds(), input, image.Point{}, draw.Src) draw.Draw(dst, input.Bounds(), input, image.Point{}, draw.Src)
draw.Draw(dst, hat.Bounds(), hat, image.Point{}, draw.Over) draw.Draw(dst, hat.Bounds(), hat, image.Point{}, draw.Over)
return dst, nil return dst, nil