UNPKG

notmebotz-tools

Version:

Sebuah Tools yang berfungsi untuk mendownload Video atau Foto dari media sosial, serta sebagai tools yang berguna untuk aplikasi kamu seperti untuk BOT

80 lines (69 loc) 2.91 kB
const WebSocket = require("ws"); const axios = require("axios"); const sharp = require("sharp"); const up = require('../../lib/uploadFile') async function img2anime(imgUrl, options = {}) { const { prompt = "(masterpiece), best quality, anime artwork", negative_prompt = "(low quality, worst quality:1.4), text, watermark", strength = 0.6, } = options; const res = await axios.get(imgUrl, { responseType: "arraybuffer" }); const imgBuffer = Buffer.from(res.data); const b64Img = imgBuffer.toString("base64"); const sessHash = Math.random().toString(36).slice(2); return new Promise((resolve, reject) => { const ws = new WebSocket("wss://pixnova.ai/demo-photo2anime/queue/join", { headers: { Origin: "https://pixnova.ai", "User-Agent": "Mozilla/5.0", Connection: "Upgrade", Upgrade: "websocket", "Sec-WebSocket-Version": "13", }, }); ws.on("message", async (data) => { const msg = JSON.parse(data.toString()); if (msg.msg === "send_hash") { ws.send(JSON.stringify({ session_hash: sessHash })); } else if (msg.msg === "send_data") { ws.send( JSON.stringify({ data: { negative_prompt, prompt, source_image: `data:image/jpeg;base64,${b64Img}`, strength, }, }) ); } else if (msg.msg === "process_completed" && msg.success) { const resultUrl = `https://oss-global.pixnova.ai/${msg.output.result[0]}`; ws.close(); // Ambil hasilnya dan ubah ke JPEG dalam buffer const resultRes = await axios.get(resultUrl, { responseType: "arraybuffer" }); const webpBuffer = Buffer.from(resultRes.data); const jpegBuffer = await sharp(webpBuffer).jpeg().toBuffer(); resolve(jpegBuffer); } else if (msg.msg === "process_completed") { ws.close(); reject("Processing failed"); } }); ws.on("error", (err) => reject(err)); }); } async function img2gtas(imgUrl) { const jpegBuffer = await img2anime(imgUrl, { prompt: "Create an image that embodies the visual style of Grand Theft Auto V (GTA V). The scene should feature a bustling urban environment with a vibrant color palette, showcasing a mix of modern architecture and palm trees. Include dynamic elements such as diverse characters engaged in various activities, vehicles in motion, and a clear blue sky. The overall composition should evoke a sense of adventure and freedom, capturing the essence of an open-world game. Emphasize realism in textures and details while incorporating a slightly exaggerated and stylized aesthetic typical of the game. Use lighting effects to create dramatic contrasts, enhancing the mood of the scene.", negative_prompt: "blurry, deformed hands, 3d render, text, error image, error color, real, error pixel, ugly pixel", strength: 0.8, }); let za = await up(jpegBuffer) return { author: "Herza", status: 200, img_url: za } } module.exports = { img2gtas }