I have searched this up on the internet however all of the results included answers where you use Image.open("somefile.py")
, however, I was unable to find how to maintain the aspect ratio and scale down the image when using ImageTk.PhotoImage(Image.open("somefile.py"))
together with the GUI library, Tkinter.
Asked
Active
Viewed 375 times
1

Sabito stands with Ukraine
- 4,271
- 8
- 34
- 56

YenProgrammer
- 11
- 1
-
1Does this answer your question? [How do I resize an image using PIL and maintain its aspect ratio?](https://stackoverflow.com/questions/273946/how-do-i-resize-an-image-using-pil-and-maintain-its-aspect-ratio) – TheLizzard Mar 05 '21 at 17:35
-
Also `ImageTk` just converts the image so that it can be used by tkinter. It doesn't change its size. – TheLizzard Mar 05 '21 at 17:36
1 Answers
2
You want the thumbnail() method:
from PIL import Image
# Open the image
im = Image.open('SomeFile.png')
# Create reduced version whilst maintaining aspect ratio
im.thumbnail((newWidth,newHeight))
# Make ImageTk.PhotoImage from resized image
tkPI = ImageTk.PhotoImage(im)

Mark Setchell
- 191,897
- 31
- 273
- 432