from PIL import Image import os def resize(im, new_width): width, height = im.size ratio = height/width new_height = int(ratio*new_width) resized_image = im.resize((new_width,new_height)) return resized_image files = os.listdir("assets") extensions = ['jpg','png','jpeg'] for file in files: ext = file.split('.')[-1] if ext in extensions: im = Image.open('assets/'+file) im_resized = resize(im, 600) new_dir = 'resized_images' if not os.path.exists(new_dir): os.makedirs(new_dir) file = f'{new_dir}/{file}.jpg' im_resized.save(file, 'png', quality=100) Here you add the photos inside another folder called "assets" then it creates another folder with the resized images. Thanks for the video!
Here you are calculating new height, to maintain aspect ratio, but i want all images to resize to 224 X 224 by maintaining aspect ratio, what more should i do after resizing images as per your code
Hello sir, i tried follow the tutorial step by step. I would love to resize a 150 px image into 1080 px however, the result is still ugly. Could anyone here give me some advices
@@thecodebear I have a small script with diffent size of photo's i want to resize all of them and put that in my tkinter script. if i send you my small script can you write the code for me. i tried it many times but unfortunetly
from PIL import Image
import os
def resize(im, new_width):
width, height = im.size
ratio = height/width
new_height = int(ratio*new_width)
resized_image = im.resize((new_width,new_height))
return resized_image
files = os.listdir("assets")
extensions = ['jpg','png','jpeg']
for file in files:
ext = file.split('.')[-1]
if ext in extensions:
im = Image.open('assets/'+file)
im_resized = resize(im, 600)
new_dir = 'resized_images'
if not os.path.exists(new_dir):
os.makedirs(new_dir)
file = f'{new_dir}/{file}.jpg'
im_resized.save(file, 'png', quality=100)
Here you add the photos inside another folder called "assets" then it creates another folder with the resized images. Thanks for the video!
awesome tutorial!
I hope you put the code in the description for your followers. Thank you and good job.
What's about fix height? Is new_width = int(ratio*new_height) ?
Here you are calculating new height, to maintain aspect ratio, but i want all images to resize to 224 X 224 by maintaining aspect ratio, what more should i do after resizing images as per your code
Aspect ratio is width/height
Can you do batch crop please
How can I resize an image from a URL?
Hello sir, i tried follow the tutorial step by step. I would love to resize a 150 px image into 1080 px however, the result is still ugly. Could anyone here give me some advices
Sir,
i have some medical images with different sizes, I want to resize all of them to 224 X 224 without loosing aspect ratio.....how to do it sir
You cant make them square shape without loosing the aspect ratio
@@thecodebear thank you sir
@@chitti9974 you can box them with padding but it becomes so blurry...
Nice video
I need your help
Yes , what is it ?
@@thecodebear I have a small script with diffent size of photo's
i want to resize all of them and put that in my tkinter script.
if i send you my small script can you write the code for me.
i tried it many times but unfortunetly
@@thecodebear I have a frame (width=100 and height=815)
how to resize my images in that size and how i can make a new folder to
put my resized images