Create rectangular images in Stable Diffusion

Most SD models are trained with 512×512 or 768×768 square images, this means they are optimized to create 1:1 aspect ratio images. Using the Inpainting option with certain extensions you can expand your square images to create proper landscape or portrait images.

Because models are trained with square images, creating a non 1:1 ar image could result in irrecoverably distorted or glitched images. An easy workaround to safely create rectangular images is to use Inpainting to expand square images as follows.

Install required extensions

  1. Install these automatic1111 plugins from the Extensions tab if you don’t have them already:
    1. Aspect Ratio selector plus
    2. ControNet
    3. Ultimate SD Upscale
  2. Add the control_v11p_sd15_inpaint.pth file to your stable-diffusion-webuid / extensions / sd-webui-controlnet / models folder.
  3. Reload the UI to refresh the interface. You should see Control Net and the Aspect Ratio selector buttons in the interface now.
SD aspect ratio selector extension

SD Aspect Ratio selector plus extension.

Expand your square image with inpainting

  1. Create a square image normally in either 512×512 or 768×768 depending on the model.
  2. Send the image to the img2img tab (or load it directly).
  3. Select the desired image aspect ratio and size but keeping the original width or height
  4. Enable Control Net Unit 0 and load the square image again there.
  5. Under Control type select the Inpaint button. The control_v11p_sd15_inpaint option will be auto-selected in your Model drop-down box.
  6. Leave the Control weight, Starting and Ending control steps options in their default values unless you absolutely know how they work.
  7. Under Resize mode select Resize and Fill.SD inpaint upscaling
  8. Click Generate to expand your square image with inpaint.


Remember that Steps, CFG Scale and your prompt will be used to infer the contents added to your image. They key here is to expand the image either vertically or horizontally only, in 256, 512 or 768 px increments, do not increase both with and height simultaneously.

ℹ Inpainting a 512×512 image with this method will result in a 512×768 or 768×512 image, with the original image centered. As of today, there is no option to expand the image to one side only, but you can expand it once, repeat the process, and crop the image to discard the undesired portion to achieve the same result.

You can repeat the process to expand your horizontally or vertically expanded image in the other direction as well, however, always use 256, 512 or 768px increments for best results.

Notice for GeForce GTX 1660 users

Expanding images with inpainting on these cards will have mixed results depending on your Nvidia driver version installed.

  • Driver version = 531: Faster driver, however, inpainting a 512×512 image to 768 or more works only once, then fail due to CUDA out of memory error. Restarting SD fixes this but this (once). No combination of command line parameters seem to fix this, leave your comments otherwise.
  • Driver version > 531: The latest driver version is 4x slower on SD, however, you can run SD without the –medvram parameter, and you can successfully inpaint+expand images without errors.

The content in this post is for general information purposes only. The information is provided by the author and/or external sources and while we endeavour to keep the information up to date and correct, we make no representations or warranties of any kind, express or implied, about the completeness, accuracy, reliability, suitability or availability with respect to the website or the information, products, services, or related graphics contained on the post for any purpose. Some of the content and images used in this post may be copyrighted by their respective owners. The use of such materials is intended to be for educational and informational purposes only, and is not intended to infringe on the copyrights of any individuals or entities. If you believe that any content or images used here violate your copyright, please contact us and we will take appropriate measures to remove or attribute the material in question.