This is an ES module for Node.js that provides uses Stable Diffusion to generate images from a given prompt using AI.
npm install stable-diffusion-es
import { generate } from "stable-diffusion-ts";
const prompt = "A black cat";
generate(prompt, (response) => {
if (response.error) {
console.log("There was an error generating the image.");
} else {
console.log("Image generated successfully!");
console.log(`Image saved at: ${response.results}`);
}
});
you can also pass a file path to save the image to.
import { generate } from "stable-diffusion-ts";
const prompt = "A black cat";
generate(prompt, (response) => {
if (response.error) {
console.log("There was an error generating the image.");
} else {
console.log("Image generated successfully!");
console.log(`Image saved at: ${response.results}`);
}
}, "path/to/save/image");
A trick to get better images is to add:
{enhanced}
at the end of your prompt.
in your package.json file.