From 7cf65b6f6a5d6de1da84bb51a641f141592a9beb Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sun, 29 Mar 2026 22:14:59 +0300 Subject: [PATCH] commands/imagepack: always use decoded dimensions --- pkg/connector/imagepack.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/pkg/connector/imagepack.go b/pkg/connector/imagepack.go index 55ceccac..05d1a54f 100644 --- a/pkg/connector/imagepack.go +++ b/pkg/connector/imagepack.go @@ -222,10 +222,15 @@ func (t *TelegramClient) synchronizeEmoji( if img.Info.MimeType == "" { img.Info.MimeType = http.DetectContentType(data) } - if img.Info.Width == 0 || img.Info.Height == 0 { - cfg, _, _ := image.DecodeConfig(bytes.NewReader(data)) - img.Info.Width = cfg.Width - img.Info.Height = cfg.Height + origWidth, origHeight := img.Info.Width, img.Info.Height + cfg, _, err := image.DecodeConfig(bytes.NewReader(data)) + if err != nil { + return nil, nil, fmt.Errorf("failed to decode image config for %s: %w", shortcode, err) + } + img.Info.Width = cfg.Width + img.Info.Height = cfg.Height + if origWidth == 0 || origHeight == 0 { + origWidth, origHeight = cfg.Width, cfg.Height } data, mime, err := normalizeImage(ctx, data, img.Info, emoji) if err != nil { @@ -263,8 +268,8 @@ func (t *TelegramClient) synchronizeEmoji( MXC: img.URL, MIMEType: img.Info.MimeType, Size: len(data), - Width: img.Info.Width, - Height: img.Info.Height, + Width: origWidth, + Height: origHeight, Timestamp: time.Now(), }) if err != nil {