DEV Community

Max Angelo Dapitilla Perin
Max Angelo Dapitilla Perin

Posted on

Answer: How do I resize an image using PIL and maintain its aspect ratio?

from PIL import Image

img = Image.open('/your image path/image.jpg') # image extension *.png,*.jpg
new_width  = 200
new_height = 300
img = img.resize((new_width, new_height), Image.ANTIALIAS)
img.save('output image name.png') # format may what you want *.png, *jpg, *.gif

Top comments (0)