I am trying to train a stable diffusion model, which receives 512 x 512
images as inputs.
I am downloading the bulk of images from the web, and they have multiple sizes and shapes, and so I need to preprocess them and convert to 512 x 512
.
If I take this 2000 × 1434
image:
And I try to resize it, with:
from PIL import Image
# Open an image file
with Image.open("path/to/Image.jpg") as im:
# Create a thumbnail of the image
im.thumbnail((512, 512))
# Save the thumbnail
im.save("path/to/Image_resized.jpg")
I get this 512 × 367
image:
But I need 512 for both width and height, without distorting the image, like you can achieve on this website:
Any ideas on how I can achieve this conversion using python?