npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pollinations

v1.0.4

Published

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

Downloads

4

Readme

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)

| Parameter | Type | Default | Description | | :-------- | :------- | :------- | :------------------------- | | images | number | 1 | Default number of images to generate when using the generate() function | | width | number | 512 | Default width for images in pixels | | height | number | 512 | Default height for images in pixels | | seed | number | -1 (-1 indicates random) | Default seed used to generate images | | nologo | number | false | Whether 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.

| Parameter | Type | Default | Description | | :-------- | :------- | :------- | :------------------------- | | prompt | string | N/A | (REQUIRED) Description of the image(s) to generate | | images | number | defaultParameters or 1 | Number of images to generate | | width | number | defaultParameters or 512 | Width for images in pixels | | height | number | defaultParameters or 512 | Height for images in pixels | | seed | number | defaultParameters or -1 | Seed to use to generate images | | nologo | number | defaultParameters or false | Whether the images should include the Pollinations logo or not |

| Name | Type | Description | | :-------- | :------- | :------------------------- | | Object.requestId | string | Unique 36-character alphanumeric string you can use to identify the generate request | | Object.prompt | string | The prompt used for the generation | | Object.width | number | The width used for the generation | | Object.height | number | The height used for the generation | | Object.seed | number | The seed used for the generation | | Object.nologo | boolean | Whether the images include the Pollinations logo or not | | Object.expectedImages | number | Requested number of images to generate | | Object.errors | number | How many errors happened during the process | | Object.images | array | Array of buffers | | Object.isComplete | boolean | true 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!