to import Pillow use this code from PIL import Image, ImageTk image.resize((w, h)) this command allows us to change the height(h) and width(w) of the image. Using Pillow library in Python Tkinter we can resize the images. You can use the same filename to overwrite the full-size image with the resized image, if that is what you want. In this section, we will learn how to resize the image in Python Tkinter. Also, notice I saved the resized image under a different name, resized_image.jpg, because I wanted to preserve the full-size image ( fullsized_image.jpg) as well. As you proceed further, we will discuss resizing with different scale factors and interpolation methods as well. You can change basewidth to any other number if you need a different width for your images. The resulting height value is saved in the variable hsize. Code: Set rows and columns Downsize the image using new width and height downwidth 800 down. The proportional height is calculated by determining what percentage 300 pixels is of the original width ( img.size) and then multiplying the original height ( img.size) by that percentage. It will resize the image according to the specified height and width. The scaling factor can either be a single floating point value, or multiple values - one along. These few lines of Python code resize an image ( fullsized_image.jpg) using Pillow to a width of 300 pixels, which is set in the variable basewidth and a height proportional to the new width. Rescale operation resizes an image by a given scaling factor.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |