![]() ![]() ![]() 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. 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. 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. Img = img.resize((basewidth, hsize), Image.ANTIALIAS) Hsize = int((float(img.size) * float(wpercent))) Here's a basic script to resize an image using the Pillow module: from PIL import Image To install Pillow, use the pip module of Python: $ python3 -m pip install Pillow Scaling by width So I looked around and found Pillow, a Python imaging library and "friendly fork" of an old library just called PIL. Some time ago, I wrote a Python script where I needed to resize a bunch of images while at the same time keeping the aspect ratio (the proportions) intact. I love Python, and I've been learning it for a while now.
0 Comments
Leave a Reply. |