1.0.4 • Published 8 months ago

pollinations v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
8 months ago

Pollinations

A Node.js package that allows you to easily generate images using Pollinations's free API.

Installation

Install pollinations to your project with npm:

npm install pollinations

Example Usage

Integrating pollinations to a Discord bot using discord.js.

npm install discord.js
  • Create a simple bot
const { Client, GatewayIntentBits, AttachmentBuilder } = require("discord.js");
const Pollinations = require("pollinations")
const pollinations = new Pollinations()

const Bot = new Client({
    intents: [
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent,
        GatewayIntentBits.DirectMessages
    ]
});

Bot.on("messageCreate", async (message) =>{
    if(message.bot) return;
    if(!message.content) return;

    if(message.content.toLowerCase().startsWith("!generate")){

        const prompt = message.content.substring("!generate".length).trim();

        if(prompt.length === 0) return message.reply(":x: Please provide a prompt.");

        message.react("✅")

        pollinations.generate({
            prompt: prompt
        })
        .then(result =>{
            const imagesBuffers = []
            result.images.forEach(image =>{
                imagesBuffers.push(
                    new AttachmentBuilder(image, {
                        name: "pollinations-image.jpg
                    })
                )
            })
            message.reply({
                content: "Here is your image",
                files: imagesBuffers
            })
        })
        .catch(error =>{
            return message.reply(":x: Something went wrong.");
        })

    }
})

Bot.login("VERY_SECRET_TOKEN")

Documentation

Initialization

const Pollinations = require("pollinations")
const pollinations = new Pollinations(defaultParameters)
ParameterTypeDefaultDescription
imagesnumber1Default number of images to generate when using the generate() function
widthnumber512Default width for images in pixels
heightnumber512Default height for images in pixels
seednumber-1 (-1 indicates random)Default seed used to generate images
nologonumberfalseWhether the images should have the Pollinations logo or not

generate()

 pollinations.generate(generateParameters).then(results)

The pollinations.generate() returns images by sending HTTPS requests to the official Pollinations website; It takes an Object parameter and return an Object.

ParameterTypeDefaultDescription
promptstringN/A(REQUIRED) Description of the image(s) to generate
imagesnumberdefaultParameters or 1Number of images to generate
widthnumberdefaultParameters or 512Width for images in pixels
heightnumberdefaultParameters or 512Height for images in pixels
seednumberdefaultParameters or -1Seed to use to generate images
nologonumberdefaultParameters or falseWhether the images should include the Pollinations logo or not
NameTypeDescription
Object.requestIdstringUnique 36-character alphanumeric string you can use to identify the generate request
Object.promptstringThe prompt used for the generation
Object.widthnumberThe width used for the generation
Object.heightnumberThe height used for the generation
Object.seednumberThe seed used for the generation
Object.nologobooleanWhether the images include the Pollinations logo or not
Object.expectedImagesnumberRequested number of images to generate
Object.errorsnumberHow many errors happened during the process
Object.imagesarrayArray of buffers
Object.isCompletebooleantrue if the number of images in the images array is the same as expectedImages

Support Discord Logo

If you're having issues with Pollinations or want to share your projects, ideas or feedbacks, you can join my support server!

1.0.4

8 months ago

1.0.3

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago

1.0.0

9 months ago