Here I just take the example of image resizing for displaying a progress bar. When we convert lots of images at a time we can use a progress bar to show how many images are resized.
Requirements:
pip install tqdm
- For Resizing images
pip install Pillow
Source Code:
progress_bar_ with_images_resizing.py
from tqdm import tqdm
from PIL import Image
import os
from time import sleep
def Resize_image(size, image):
if os.path.isfile(image):
try:
im = Image.open(image)
im.thumbnail(size, Image.ANTIALIAS)
im.save("resize/" + str(image) + ".jpg")
except Exception as ex:
print(f"Error: {str(ex)} to {image}")
path = input("Enter Path to images : ")
size = input("Size Height , Width : ")
size = tuple(map(int, size.split(",")))
os.chdir(path)
list_images = os.listdir(path)
if "resize" not in list_images:
os.mkdir("resize")
for image in tqdm(list_images, desc="Resizing Images"):
Resize_image(size, image)
sleep(0.1)
print("Resizing Completed!")
Code language: JavaScript (javascript)