Image resize fails when Froce flag is set

This commit is contained in:
mikolaj 2012-08-18 17:27:22 +01:00
parent e990a6c70c
commit 676a7bf712
2 changed files with 27 additions and 3 deletions

View File

@ -1108,6 +1108,7 @@ class ImageGridFsProxy(GridFSProxy):
try:
img = Image.open(file_obj)
img_format = img.format
except:
raise ValidationError('Invalid image')
@ -1142,20 +1143,20 @@ class ImageGridFsProxy(GridFSProxy):
if thumbnail:
thumb_id = self._put_thumbnail(thumbnail,
img.format)
img_format)
else:
thumb_id = None
w, h = img.size
io = StringIO()
img.save(io, img.format)
img.save(io, img_format)
io.seek(0)
return super(ImageGridFsProxy, self).put(io,
width=w,
height=h,
format=img.format,
format=img_format,
thumbnail_id=thumb_id,
**kwargs)

View File

@ -1851,6 +1851,29 @@ class FieldTest(unittest.TestCase):
t.image.delete()
def test_image_field_resize_force(self):
if PY3:
raise SkipTest('PIL does not have Python 3 support')
class TestImage(Document):
image = ImageField(size=(185, 37, True))
TestImage.drop_collection()
t = TestImage()
t.image.put(open(TEST_IMAGE_PATH, 'r'))
t.save()
t = TestImage.objects.first()
self.assertEquals(t.image.format, 'PNG')
w, h = t.image.size
self.assertEquals(w, 185)
self.assertEquals(h, 37)
t.image.delete()
def test_image_field_thumbnail(self):
if PY3:
raise SkipTest('PIL does not have Python 3 support')