Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

pollinations

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pollinations

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

  • 1.0.4
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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.

  • Install 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!

FAQs

Package last updated on 31 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc