jdriscoll/django-imagekit — Issue #42: Images Unnecessarily Regenerated
Author: matthewwithanm
Created: 2011-11-01 23:13:45+00:00
State: open
Labels: 1.0

A nasty bug in the extension suggestion algorithm can cause images to be unnecessarily regenerated and even duplicated on the filesystem.

The reason is that IK relies on PIL's `EXTENSION` list to map formats to extensions. However, under normal circumstances, this list isn't populated until an image is opened or saved. Therefore, the first time a spec is accessed (assuming you haven't already used PIL to do something else), you can wind up with a different (wrong) suggested extension. IK will then check for the existence of the file with the wrong extension. Of course, it won't exist, so IK will generate a new image. Since `Image.open` will have been called in the course of generating the image, the new suggested filename will be correct. This process will be repeated exactly each subsequent time (since the file with the incorrect extension still won't exist) but since a file with the correct extension will already exist, the storage backend will append a count, resulting in a filesystem full of duplicate images!