
Company News
Andrew Becherer Joins Socket as Chief Information Security Officer
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.
@themaximalist/imagine.js
Advanced tools
Imagine.js is a simple AI image generator library for Node.js. It works with local models like Automatic1111 and remote models like Replicate and Stability.
await Imagine("a red rose"); // Buffer(...)
![]() | ![]() | ![]() | ![]() |
Features
a1111, replicate, stability)Stable Diffusion modelsReplicate or Stability AIInstall Imagine.js from NPM:
npm install @themaximalist/imagine.js
For local models, ensure an Automatic1111 instance is running.
For remote models, make sure you have REPLICATE_API_KEY or STABILITY_API_KEY set in your environment variables.
export STABILITY_API_KEY=...
export REPLICATE_API_KEY=...
Imagine.js takes a text prompt and returns an image buffer.
const image = await Imagine("futuristic sci-fi city"); // image buffer
fs.writeFileSync("city.png", image);
The buffer can be saved to disk, written to a database, etc...
Specify a different image generator service, a1111, replicate or stability.
await Imagine("a red rose"); // defaults to a1111
await Imagine("a red rose", { service: "replicate"} );
await Imagine("a red rose", { service: "stability"} );
Making it easy to switch providers ensures you can try lots of combinations and prevent getting locked in!
Running your prompt through an LLM first can produce great results. Imagine.js is easy to combine with LLM.js to quickly remix and increase the quality of your prompts.
const LLM = require("@themaximalist/llm.js");
const llm = new LLM();
llm.user(`You are an image remixing box.
Given a text prompt, return a remixed prompt with more detail about the properties and qualities of a scene.
Only return a single prompt.`);
llm.assistant("Ok got it. What is your prompt?");
const prompt = await llm.chat("a red rose");
// a dew-kissed red rose in the early morning light, its petals ...
const buffer = await Imagine(prompt);
fs.writeFileSync("rose.png", buffer);
You can run this over and over and iterate with the LLM and Image Model towards a better and better result. Check out AI.js and Images Bot for a real-world examples of this.
The Imagine.js API is a simple function you call with your text prompt, and an optional config object.
await Imagine(
input, // Text input for image generation
{
service: "stability", // Embedding service
model: "stable-diffusion-xl-beta-v2-2-2", // Embedding model
seed: 100, // Stabilize image generation
}
);
Options
service <string>: Image generation service provider. Default is a111, a local provider. Other providers are stability and replicate.model <string>: Image generation model. Default is a111 with Stable Diffusionseed <int>: Stabilize image generation making it more deterministic. No default.Response
Imagine.js returns an image Buffer. Typically you save this as a png file, which let's you view it.
const buffer = await Imagine("a red rose");
fs.writeFileSync("rose.png", buffer);
The Imagine.js API ensures you have a simple way to use different image generators in the same interface.
Imagine.js uses the debug npm module with the imagine.js namespace.
View debug logs by setting the DEBUG environment variable.
> DEBUG=imagine.js*
> node src/imagine_images.js
# debug logs
Imagine.js is currently used in the following projects:
MIT
Created by The Maximalist, see our open-source projects.
FAQs
Simple AI Image Generation
We found that @themaximalist/imagine.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Company News
Socket’s first CISO brings deep experience securing high-growth SaaS companies as open source supply chain threats accelerate.

Company News
Replit is integrating Socket Firewall into its AI-powered development experience to help protect builders from malicious open source packages.

Security News
npm confirmed a tooling bug incorrectly marked several one-character packages as security holders and said it was working on a rollback.