Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const sharp = require('sharp');
- exports.run = {
- usage: ['swap'],
- use: 'reply media & enter url Img',
- category: 'converter',
- async: async (m, { client, text, Func, Scraper }) => {
- let q = m.quoted ? m.quoted : m;
- let mime = (q.msg || q).mimetype || '';
- if (!text) return m.reply("Masukkan URL foto untuk dilakukan swap face, gunakan fitur #tourl");
- if (!mime) return m.reply('Harap balas dengan media');
- client.sendReact(m.chat, '🕒', m.key);
- try {
- let media = await q.download();
- let link = await Scraper.uploadImageV3(media);
- let url = link.data.url;
- const result = `https://anabot.my.id/api/ai/swapFace?imageUrlTarget=${url}&imageUrlSource=${text}&apikey=Klamsky`;
- let buffer = await Func.fetchBuffer(result);
- sharp(buffer)
- .metadata()
- .then(({ width, height }) => {
- let cropWidth = Math.floor(width / 3);
- let cropHeight = height;
- let left = width - cropWidth;
- return sharp(buffer)
- .extract({ left: left, top: 0, width: cropWidth, height: cropHeight })
- .toBuffer();
- })
- .then(croppedBuffer => {
- client.sendFile(m.chat, croppedBuffer, 'swap.jpg', 'Berhasil melakukan swap face dan crop.', m);
- })
- .catch(err => {
- console.error(err);
- m.reply('Terjadi kesalahan saat melakukan crop pada gambar.');
- });
- } catch (error) {
- console.error(error);
- m.reply('Terjadi kesalahan saat melakukan swap face.');
- }
- },
- error: false,
- cache: true,
- location: __filename
- };
Add Comment
Please, Sign In to add comment