Pregunta

I already listed all .jpg files in a certain directory and used the Image.open to find the size of the image. Is there a way with PIL to do the sam only for each individual file in that certain directory?

    os.chdir('randomDir')
    im=Image.open("01080_creteclifs_1680x1050.jpg")
    print(im.format, im.size)

Is there a similar way for the whole folder, dir or whatever?

¿Fue útil?

Solución

I'm afraid PIL only works on a file basis, so you'll have to code the rest yourself. Fortunately, this is easy with Python:

for path, dirs, files in os.walk('randomDir'):
    for fpath in files:
        im = Image.open(os.path.join(path, fpath))
        print(im.format, im.size)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top