Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- import os
- print("Hello there! I am an image resolution and size calculator")
- print("Please make sure that folder is located on Desktop")
- folder_name = input("Please enter folder name that contains the images you wish to check:")
- path = "/home/pi/Desktop/{0}".format(folder_name)
- #This part is to list all files in the folder. I will later add a check to make sure that the file is an image
- files = []
- # r=root, d=directories, f = files
- for r, d, f in os.walk(path):
- for file in f:
- files.append(os.path.join(r, file))
- #To get image size, bit depth and calculate resolution
- for i in files:
- im_new = Image.open(i)
- width, height = im_new.size
- mode_to_bpp = {"1": 1, "L": 8, "P": 8, "RGB": 24, "RGBA": 32, "CMYK": 32, "YCbCr": 24, "LAB": 24, "HSV": 24, "I": 32, "F": 32}
- bpp = mode_to_bpp[im_new.mode]
- resolution = width * height * bpp
- print("Image path/name is: ", i)
- print("The image resolution is: ", width, " x ", height, " x", bpp)
- print("Bit depth is: ", bpp)
- print("The resolution is: ", resolution,"\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement