Python image library

Status
You're currently viewing only dolphyjazz's posts. Click here to go back to viewing the entire thread.
Not open for further replies.
I'm trying to iterate through all the pictures in a folder and resize them using the python thumbnail function. I get an error: IOError: cannot identify image file. Can anyone help me out on this one? It seems that it's not seeing the file as an image.

Code:
import Image, os
 
for filename in os.listdir('.'):
    img = Image.open(filename)
    img.thumbnail( (200,200) )
    out = file(os.path.splitext(filename)[0]+"_thumb.jpg", "w")
    try:
        img.save(out, "JPEG")
    finally:
        out.close()
 
dredphul":369wyg6l said:
Debugging issues with scripts like this is easier if you have output to analyze.

For something as simple as the presented code, simply adding a 'print filename' statement would have gotten you past the first problem.

If you had outputted the file name as the script progressed, you'd know if a particular file couldn't be resized and you'd be able to look at the file and see if the file was corrupted or couldn't be processed due to some other issue.

I did do that and it would print the name of the jpg file. I read that you should open it in binary mode but by that time I just went another route.
 
Status
You're currently viewing only dolphyjazz's posts. Click here to go back to viewing the entire thread.
Not open for further replies.