puter.ai.txt2img()
Given a prompt, generate an image using AI.
puter.ai.txt2img(prompt, testMode = false)
prompt
(String) (required)
A string containing the prompt you want to generate an image from.
testMode
(Boolean) (Optional)
A boolean indicating whether you want to use the test API. Defaults to false
. This is useful for testing your code without using up API credits.
A Promise
that will resolve to an image data URL when the image has been generated.
Generate an image of a cat using DALL·E 3
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<script>
// Generate an image of a cat using DALL·E 3. Please note that testMode is set to true so that you can test this code without using up API credits.
puter.ai.txt2img('A picture of a cat.', true).then((image)=>{
document.body.appendChild(image);
});
</script>
</body>
</html>