use resize.Thumbnail mode instead of calculating size

This commit is contained in:
Antoni Sawicki 2024-07-02 02:24:01 -07:00
parent 26b3c21aa7
commit c1ffd71e25

4
txt.go
View File

@ -194,9 +194,7 @@ func smallGif(src []byte) ([]byte, error) {
if err != nil {
return nil, fmt.Errorf("image decode problem: %v", err)
}
if img.Bounds().Max.X-img.Bounds().Min.X > *txtImgSize { // this should come from the form
img = resize.Resize(uint(*txtImgSize), 0, img, resize.NearestNeighbor)
}
img = resize.Thumbnail(uint(*txtImgSize), uint(*txtImgSize), img, resize.NearestNeighbor)
var gifBuf bytes.Buffer
err = gif.Encode(&gifBuf, gifPalette(img, 216), &gif.Options{})
if err != nil {