Compress and Resize Images in WhatsApp using Node.js
import jimp from 'jimp'; import uploadImage from '../lib/uploadImage.js'; import uploadFile from '../lib/uploadFile.js';
const handler = async (m, { conn, usedPrefix, args }) => { let towidth = args[0]; let toheight = args[1]; if (!towidth) throw 'size width?'; if (!toheight) throw 'size height?';
let q = m.quoted ? m.quoted : m; let mime = (q.msg || q).mimetype || ''; if (!mime) throw 'where the media?';
let media = await q.download();
let isMedia = /image/(png|jpe?g|gif)|video/mp4/.test(mime);
if (!isMedia) throw Mime ${mime} tidak didukung;
let link = await (isMedia ? uploadImage : uploadImage)(media);
let source = await jimp.read(await link); let size = { before: { height: await source.getHeight(), width: await source.getWidth(), }, after: { height: toheight, width: towidth, }, }; let compres = await conn.resize(link, towidth - 0, toheight - 0); let linkcompres = await (isMedia ? uploadImage : uploadImage)(compres);
conn.sendFile(
m.chat,
compres,
null,
- *Compress Resize* -\n\n*• BEFORE*\n> Width : ${size.before.width}\n> Height : ${size.before.height}\n\n*• AFTER*\n> Width : ${size.after.width}\n> Hegiht : ${size.after.height}\n\n*• LINK*\n> Original : ${link}\n> Compress : ${linkcompres},
m
);
};
handler.help = ['resize
export default handler;
原文地址: https://www.cveoy.top/t/topic/hiqT 著作权归作者所有。请勿转载和采集!