Advertisement
kaly1

Image size calculator

Jun 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. from PIL import Image
  2. import os
  3.  
  4. print("Hello there! I am an image resolution and size calculator")
  5. print("Please make sure that folder is located on Desktop")
  6. folder_name = input("Please enter folder name that contains the images you wish to check:")
  7. path = "/home/pi/Desktop/{0}".format(folder_name)
  8.  
  9. #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
  10. files = []
  11. # r=root, d=directories, f = files
  12. for r, d, f in os.walk(path):
  13. for file in f:
  14. files.append(os.path.join(r, file))
  15.  
  16. #To get image size, bit depth and calculate resolution
  17. for i in files:
  18. im_new = Image.open(i)
  19. width, height = im_new.size
  20. 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}
  21. bpp = mode_to_bpp[im_new.mode]
  22. resolution = width * height * bpp
  23. print("Image path/name is: ", i)
  24. print("The image resolution is: ", width, " x ", height, " x", bpp)
  25. print("Bit depth is: ", bpp)
  26. print("The resolution is: ", resolution,"\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement