imagemin / imagemin-webp

WebP plugin for imagemin
MIT License
494 stars 45 forks source link

Resize or crop #37

Open sasu08 opened 3 years ago

sasu08 commented 3 years ago

Hi! How are you? Can you tell me how to autosize the images? I'm using a whatsapp bot to make stickers, but If I don't receive an 1:1 relation image, the bot autosizes so ugly.

The current code is:

if (messageType == MessageType.image && m.message.imageMessage.url && ((m.message.imageMessage.caption == "!sticker") || (m.message.imageMessage.caption == "!Sticker"))) { let imageBuffer = await conn.downloadMediaMessage(m); let sticker = await imageminWebp({ preset: "icon" } })(imageBuffer); await conn.sendMessage(m.key.remoteJid, sticker, MessageType.sticker); console.log("Sticker enviado a : " + m.key.remoteJid); }

I tried:

let sticker = await imageminWebp({ preset: "icon", crop: {x:512,y:512, width:512, height:512 } })(imageBuffer); await conn.sendMessage(m.key.remoteJid, sticker, MessageType.sticker);

but throws:

UnhandledPromiseRejectionWarning: Error: Error! Cannot crop picture

Can you help me? Thank you!