Skip to content

Commit 6e7dd51

Browse files
committed
fix: preserve animation in GIF and WebP stickers
1 parent f8b1c6e commit 6e7dd51

1 file changed

Lines changed: 9 additions & 10 deletions

File tree

src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2703,8 +2703,7 @@ export class BaileysStartupService extends ChannelStartupService {
27032703
imageBuffer = Buffer.from(response.data, 'binary');
27042704
}
27052705

2706-
const isAnimated = image.includes('.gif') ||
2707-
(image.includes('.webp') && this.isAnimatedWebp(imageBuffer));
2706+
const isAnimated = this.isAnimated(image, imageBuffer);
27082707

27092708
if (isAnimated) {
27102709
return await sharp(imageBuffer, { animated: true })
@@ -2722,14 +2721,14 @@ export class BaileysStartupService extends ChannelStartupService {
27222721
private isAnimatedWebp(buffer: Buffer): boolean {
27232722
if (buffer.length < 12) return false;
27242723

2725-
for (let i = 0; i < buffer.length - 4; i++) {
2726-
if (buffer[i] === 0x41 && // 'A'
2727-
buffer[i + 1] === 0x4E && // 'N'
2728-
buffer[i + 2] === 0x49 && // 'I'
2729-
buffer[i + 3] === 0x4D) { // 'M'
2730-
return true;
2731-
}
2732-
}
2724+
return buffer.indexOf(Buffer.from('ANIM')) !== -1;
2725+
}
2726+
2727+
private isAnimated(image: string, buffer: Buffer): boolean {
2728+
if (image.includes('.gif')) return true;
2729+
2730+
if (image.includes('.webp')) return this.isAnimatedWebp(buffer);
2731+
27332732
return false;
27342733
}
27352734

0 commit comments

Comments
 (0)