How to use Text2Image
Harness the power of the GenAI API to generate images from text prompts with the Picsart TypeScript SDK. This guide provides a detailed example of using the text2Image method, allowing you to create customized images based on specific prompts. Generate multiple images by specifying the count, and use optional negative prompts to refine the output. Enhance your applications with this powerful feature and explore the creative possibilities of text-based image generation.
Before you start
Check these out before you start
Generate Images
One of the powerful features of the GenAI API is the ability to generate images from text prompts. You can use the text2Image
method to create images based on specific prompts. Here’s how to do it:
const result = await genaiApi.text2Image(
new Text2ImageRequest()
.setCount(10) // Specify the number of images to generate
.setPrompt("coding all the time") // The main prompt for the image generation
.setNegativePrompt("relax and rest") // Optional prompt to guide the generation away from certain themes
);
console.log(result.images); // Array of generated images
In this example, the API will generate 10 images based on the prompt "coding all the time," while avoiding themes related to "relax and rest." The generated images will be available in the result.images
array.
Process & Enhance generated images
Once an images are created, you can perform various manipulations:
For more examples, check out the TypeScript SDK Repository.
Updated 2 months ago