media: fix sticker dimensions

This commit is contained in:
Tulir Asokan
2026-03-18 21:30:24 +02:00
parent 7baed1c77b
commit 98936fdf7a

View File

@@ -137,9 +137,25 @@ func (t *Transferer) WithFilename(filename string) *Transferer {
// WithStickerConfig sets the animated sticker config for the [Transferer].
func (t *Transferer) WithStickerConfig(cfg AnimatedStickerConfig) *Transferer {
t.animatedStickerConfig = &cfg
t.adjustStickerSize()
return t
}
func (t *Transferer) adjustStickerSize() {
if (t.fileInfo.Width < 256 && t.fileInfo.Height < 256) || t.animatedStickerConfig == nil {
return
}
if t.fileInfo.Width == t.fileInfo.Height {
t.fileInfo.Width, t.fileInfo.Height = 256, 256
} else if t.fileInfo.Width > t.fileInfo.Height {
t.fileInfo.Height = t.fileInfo.Height * 256 / t.fileInfo.Width
t.fileInfo.Width = 256
} else {
t.fileInfo.Width = t.fileInfo.Width * 256 / t.fileInfo.Height
t.fileInfo.Height = 256
}
}
func (t *Transferer) WithMIMEType(mimeType string) *Transferer {
t.fileInfo.MimeType = mimeType
return t
@@ -160,6 +176,7 @@ func (t *Transferer) WithVideo(attr *tg.DocumentAttributeVideo) *Transferer {
func (t *Transferer) WithImageSize(attr *tg.DocumentAttributeImageSize) *Transferer {
t.fileInfo.Width, t.fileInfo.Height = attr.W, attr.H
t.adjustStickerSize()
return t
}