commands/imagepack: always use decoded dimensions

This commit is contained in:
Tulir Asokan
2026-03-29 22:14:59 +03:00
parent a5a3b9f380
commit 7cf65b6f6a
+11 -6
View File
@@ -222,10 +222,15 @@ func (t *TelegramClient) synchronizeEmoji(
if img.Info.MimeType == "" { if img.Info.MimeType == "" {
img.Info.MimeType = http.DetectContentType(data) img.Info.MimeType = http.DetectContentType(data)
} }
if img.Info.Width == 0 || img.Info.Height == 0 { origWidth, origHeight := img.Info.Width, img.Info.Height
cfg, _, _ := image.DecodeConfig(bytes.NewReader(data)) cfg, _, err := image.DecodeConfig(bytes.NewReader(data))
img.Info.Width = cfg.Width if err != nil {
img.Info.Height = cfg.Height 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) data, mime, err := normalizeImage(ctx, data, img.Info, emoji)
if err != nil { if err != nil {
@@ -263,8 +268,8 @@ func (t *TelegramClient) synchronizeEmoji(
MXC: img.URL, MXC: img.URL,
MIMEType: img.Info.MimeType, MIMEType: img.Info.MimeType,
Size: len(data), Size: len(data),
Width: img.Info.Width, Width: origWidth,
Height: img.Info.Height, Height: origHeight,
Timestamp: time.Now(), Timestamp: time.Now(),
}) })
if err != nil { if err != nil {