Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https://pillow.readthedocs.io/en/stable/handbook/tutorial.html
- # https://www.codespeedy.com/how-to-iterate-over-files-in-a-given-directory-in-python/
- # https://stackoverflow.com/questions/1996577/how-can-i-get-the-depth-of-a-jpg-file
- import os
- from PIL import Image
- # folder|directory to iterate through.
- dirloc = r"C:\location\of\images"
- # a mode conversion table
- mode_to_bpp = {'1':1, 'L':8, 'P':8, 'RGB':24, 'RGBA':32, 'CMYK':32, 'YCbCr':24, 'I':32, 'F':32}
- for file in os.scandir(dirloc):
- try:
- with Image.open(file.path) as im:
- # print filename, image format, image dimentions
- print(f" File: {file} | Image Format: {im.format} | Dimensions: {im.size} | Colour format(bit depth): {im.mode}({mode_to_bpp[im.mode]})")
- imgsize = im.size[0] * im.size[1] * mode_to_bpp[im.mode]
- print(f" - Image Size {imgsize} bits, ({int(imgsize*0.125)} bytes)")
- except OSError:
- pass
Add Comment
Please, Sign In to add comment