From 98936fdf7a5d15d96a78a95d2f74cf44861af932 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 18 Mar 2026 21:30:24 +0200 Subject: [PATCH] media: fix sticker dimensions --- pkg/connector/media/transfer.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/pkg/connector/media/transfer.go b/pkg/connector/media/transfer.go index c4ac2243..46f86c97 100644 --- a/pkg/connector/media/transfer.go +++ b/pkg/connector/media/transfer.go @@ -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 }