![]() However in our scenario, we would like not only to reduce the size of the images but also to compress them, therefore we will add on the following paramter to this line: img. How To Resize & Compress Multiple Images In The Current Workng Directory Then we loop over every image, open it and then resize the image. # img.save('resized-image_'+image, optimize=True) # We would run the command below to save the images: png files that have the word example in their name. Multiple_images = įirstly we list all of the files and folders inside of the current working directory. How To Resize Multiple Images In The Current Working Directory directory_files = os.listdir() Size to preserve the aspect of the image picture = Image.open('example-image.jpg') This method calculates an appropriate thumbnail Image to contain a thumbnail version of itself, no larger than It is also possible for us to create a thumbnail image of an image using: img.thumbnail(size, resample=3, reducing_gap=2.0) How To Create A Thumbnail Whilst Preserving The Aspect Ratio Image = image.resize((wsize, base_height), ) Wsize = int((float(image.size) * float(hpercent))) Hpercent = (base_height / float(image.size)) Image = Image.open(‘fullsized_image.jpg') We can also do the exact opposite and get a specified height with the following code: base_height = 360 The image is then saved with image.save(‘image_name.jpg’).Then we resize the image based on the two values (base_width and hsize).This provides us with a ratio number that we can times by the height to get the correct height for producing our base_width.We calculate the aspect ratio for width by doing: base_width / the images existing width. ![]()
0 Comments
Leave a Reply. |