mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-17 05:40:25 +00:00
Increase MAXBLOCK on save failure
Under certain circumstances, saving a JPEG may fail if MAXBLOCK isn't large enough, so we (temporarily) increase it. This should fix #50.
This commit is contained in:
parent
486fb51a1e
commit
dd7ae5a8e4
1 changed files with 8 additions and 2 deletions
|
|
@ -4,7 +4,7 @@ import types
|
|||
|
||||
from django.utils.functional import wraps
|
||||
|
||||
from imagekit.lib import Image
|
||||
from imagekit.lib import Image, ImageFile
|
||||
|
||||
|
||||
def img_to_fobj(img, format, **kwargs):
|
||||
|
|
@ -17,7 +17,13 @@ def img_to_fobj(img, format, **kwargs):
|
|||
else:
|
||||
img = img.convert('RGB')
|
||||
|
||||
img.save(tmp, format, **kwargs)
|
||||
try:
|
||||
img.save(tmp, format, **kwargs)
|
||||
except IOError:
|
||||
old_maxblock = ImageFile.MAXBLOCK
|
||||
ImageFile.MAXBLOCK = img.size[0] * img.size[1]
|
||||
img.save(tmp, format, **kwargs)
|
||||
ImageFile.MAXBLOCK = old_maxblock
|
||||
tmp.seek(0)
|
||||
return tmp
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue