I’m using PIL
im = Image.open(teh_file) if im: colors = im.resize( (1,1), Image.ANTIALIAS).getpixel((0,0)) # simple way to get average color red = colors[0] # and so on, some operations on color data
The problem is, on a few (very few, particulary don’t know why those exactly, simple jpegs) I get ‘unsubscriptable object’ on line ‘colors[0]’. Tried:
if colors:
gets true and goes on.
if len(colors):
gives ‘len() of unsized object’
- What condition should I apply not to get this exception?
- What’s the cause of the problem?
From the PIL docs:
So it seems that some of your images are multilayer, and some are single-layer.