mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -06:00
fix: preserve animation in GIF and WebP stickers
This commit is contained in:
parent
f8b1c6e0fa
commit
6e7dd51679
@ -2703,8 +2703,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
imageBuffer = Buffer.from(response.data, 'binary');
|
||||
}
|
||||
|
||||
const isAnimated = image.includes('.gif') ||
|
||||
(image.includes('.webp') && this.isAnimatedWebp(imageBuffer));
|
||||
const isAnimated = this.isAnimated(image, imageBuffer);
|
||||
|
||||
if (isAnimated) {
|
||||
return await sharp(imageBuffer, { animated: true })
|
||||
@ -2722,14 +2721,14 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
private isAnimatedWebp(buffer: Buffer): boolean {
|
||||
if (buffer.length < 12) return false;
|
||||
|
||||
for (let i = 0; i < buffer.length - 4; i++) {
|
||||
if (buffer[i] === 0x41 && // 'A'
|
||||
buffer[i + 1] === 0x4E && // 'N'
|
||||
buffer[i + 2] === 0x49 && // 'I'
|
||||
buffer[i + 3] === 0x4D) { // 'M'
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return buffer.indexOf(Buffer.from('ANIM')) !== -1;
|
||||
}
|
||||
|
||||
private isAnimated(image: string, buffer: Buffer): boolean {
|
||||
if (image.includes('.gif')) return true;
|
||||
|
||||
if (image.includes('.webp')) return this.isAnimatedWebp(buffer);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user