Ayogiakbar

Generator Image - Gen Ai

Aug 29th, 2025
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Generator Image - Gen Ai
  3.  * Author  : gienetic
  4.  * Base    : https://play.google.com/store/apps/details?id=com.sparksolutionz.genai
  5.  */
  6.  
  7. const axios = require("axios");
  8.  
  9. /**
  10.  * Generate image from Pollinations AI
  11.  * @param {string} prompt - teks prompt
  12.  * @param {string} model - model AI (flux, sdxl, midjourney, anime, realistic, turbo)
  13.  * @param {object} opts - { width, height, seed, nologo, enhance, hidewatermark }
  14.  * @returns {Promise<Buffer>} - image buffer
  15.  */
  16. async function generatePollinations(prompt, model = "flux", opts = {}) {
  17.   const {
  18.     width = 960,
  19.     height = 1280,
  20.     seed = Math.floor(Math.random() * 999999),
  21.     nologo = true,
  22.     enhance = true,
  23.     hidewatermark = true,
  24.   } = opts;
  25.  
  26.   try {
  27.     const query = new URLSearchParams({
  28.       model,
  29.       width,
  30.       height,
  31.       seed,
  32.     });
  33.  
  34.     if (nologo) query.set("nologo", "true");
  35.     if (enhance) query.set("enhance", "true");
  36.     if (hidewatermark) query.set("hidewatermark", "true");
  37.  
  38.     const url = `https://image.pollinations.ai/prompt/${encodeURIComponent(
  39.       prompt
  40.     )}?${query.toString()}`;
  41.  
  42.     const res = await axios.get(url, {
  43.       responseType: "arraybuffer",
  44.     });
  45.  
  46.     return Buffer.from(res.data, "binary");
  47.   } catch (err) {
  48.     console.error("❌ Gagal generate image:", err.message);
  49.     throw new Error("Gagal generate image dari Pollinations");
  50.   }
  51. }
  52.  
  53. module.exports = { generatePollinations };
  54.  
  55. //Contoh Pemanggilan
  56. //await generatePollinations(text, "flux");
Advertisement
Add Comment
Please, Sign In to add comment