I'm trying to resize images. It works fine, but my ImageField, which is to_field
, is opening but not closing. So I have an error too many open files
. I tried some work-around solutions but I wasn't able to fix the problem. Here is the code:
if( to_field.width != size[0] and to_field.height != size[1] ):
to_field.open()
image = Image.open(StringIO(to_field.read()))
old_file_path = to_field.path
image.resize(size).save(to_field.path)
Any advice??