Skip to content

Commit

Permalink
Fix: add padding to animated sticker instead of scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
akshettrj committed Feb 15, 2023
1 parent 3f2c4f7 commit 8729d43
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions utils/stickers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TGSConvertToWebp(tgsStickerData []byte) ([]byte, error) {
return nil, fmt.Errorf("sticker has a lot of data which cannot be handled by WhatsApp")
}

func WebmConvertToWebp(webmStickerData []byte) ([]byte, error) {
func WebmConvertToWebp(webmStickerData []byte, scale, pad string) ([]byte, error) {

var (
currTime = strconv.FormatInt(time.Now().Unix(), 10)
Expand All @@ -52,7 +52,7 @@ func WebmConvertToWebp(webmStickerData []byte) ([]byte, error) {
cmd := exec.Command(state.State.Config.FfmpegExecutable,
"-i", inputPath,
"-fs", "800000",
"-vf", "fps=15,scale=512:512",
"-vf", fmt.Sprintf("fps=15,scale=%s,pad=%s", scale, pad),
outputPath,
)

Expand Down
16 changes: 15 additions & 1 deletion utils/telegram.go
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,21 @@ func TgSendToWhatsApp(b *gotgbot.Bot, c *ext.Context,
return TgReplyWithErrorByContext(b, c, "Failed to convert TGS sticker to WebP", err)
}
} else if msgToForward.Sticker.IsVideo && !cfg.Telegram.SkipVideoStickers {
stickerBytes, err = WebmConvertToWebp(stickerBytes)

var scale, pad string

if msgToForward.Sticker.Height == 512 && msgToForward.Sticker.Width == 512 {
scale = "512:512"
pad = "0:0:0:0"
} else if msgToForward.Sticker.Height == 512 {
scale = "-1:512"
pad = fmt.Sprintf("512:512:%v:0", 512-msgToForward.Sticker.Width/2)
} else {
scale = "512:-1"
pad = fmt.Sprintf("512:512:0:%v", 512-msgToForward.Sticker.Height/2)
}

stickerBytes, err = WebmConvertToWebp(stickerBytes, scale, pad)
if err != nil {
return TgReplyWithErrorByContext(b, c, "Failed to convert WEBM sticker to GIF", err)
}
Expand Down

0 comments on commit 8729d43

Please sign in to comment.