{"id":5378,"date":"2026-03-10T07:09:48","date_gmt":"2026-03-10T11:09:48","guid":{"rendered":"https:\/\/dft.wiki\/?p=5378"},"modified":"2026-03-10T20:53:03","modified_gmt":"2026-03-11T00:53:03","slug":"ai-image-generation-text-to-image","status":"publish","type":"post","link":"https:\/\/dft.wiki\/?p=5378","title":{"rendered":"AI Image Generation &#8211; Text-to-Image"},"content":{"rendered":"<p><strong>TEXT-TO-IMAGE<\/strong><\/p>\n<p>In the basic script below, the <code>diffusers<\/code> library is imported, and the <code>DiffusionPipeline<\/code> class is used to load the pre-trained model. A pipeline (<code>pipe<\/code>) then executes the generation task by processing the prompt and returning the resulting image.<\/p>\n<pre>from diffusers import DiffusionPipeline\r\n\r\npipe = DiffusionPipeline.from_pretrained(\r\n    \"<strong>stabilityai\/stable-diffusion-xl-base-1.0<\/strong>\", \r\n)\r\n\r\nprompt = \"<strong>A red flower.<\/strong>\"\r\n\r\nimage = pipe(\r\n    prompt=prompt\r\n).images[0]\r\n\r\nimage.save(\"<strong>output.png<\/strong>\")\r\n<\/pre>\n<p>Typically, several additional parameters are configured within the pipeline to refine the results. See the example below:<\/p>\n<pre>image = pipe(\r\n    prompt=<strong>\"A green cat.\"<\/strong>,\r\n    negative_prompt=<strong>\"red flower\"<\/strong>,\r\n    num_inference_steps=<strong>18<\/strong>,\r\n    guidance_scale=<strong>8<\/strong>,\r\n    width=<strong>512<\/strong>,\r\n    height=<strong>512<\/strong>,\r\n).images[0]<\/pre>\n<p>The following image illustrates the output of all 18 inference steps:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5360\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/text-to-image.png\" alt=\"\" width=\"1212\" height=\"271\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/text-to-image.png 1212w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/text-to-image-300x67.png 300w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/text-to-image-1024x229.png 1024w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/text-to-image-768x172.png 768w\" sizes=\"auto, (max-width: 1212px) 100vw, 1212px\" \/><\/p>\n<p>For more details and reference, see my own code used to generate the images above at <strong>Text2Image<\/strong> [<a href=\"https:\/\/github.com\/davift\/Text2Image\">Link<\/a>].<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-5368\" src=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/Screenshot_2026-03-09_10-34-16.png\" alt=\"\" width=\"973\" height=\"657\" srcset=\"https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/Screenshot_2026-03-09_10-34-16.png 973w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/Screenshot_2026-03-09_10-34-16-300x203.png 300w, https:\/\/dft.wiki\/wp-content\/uploads\/sites\/15\/2026\/03\/Screenshot_2026-03-09_10-34-16-768x519.png 768w\" sizes=\"auto, (max-width: 973px) 100vw, 973px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>TEXT-TO-IMAGE In the basic script below, the diffusers library is imported, and the DiffusionPipeline class [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-5378","post","type-post","status-publish","format-standard","hentry","category-ai"],"_links":{"self":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/5378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5378"}],"version-history":[{"count":3,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/5378\/revisions"}],"predecessor-version":[{"id":5410,"href":"https:\/\/dft.wiki\/index.php?rest_route=\/wp\/v2\/posts\/5378\/revisions\/5410"}],"wp:attachment":[{"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dft.wiki\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}