Merge pull request #548 from yograterol/feature-progressive-jpeg
Feature for progressive JPEG. Issue #486
This commit is contained in:
		| @@ -1312,6 +1312,16 @@ class ImageGridFsProxy(GridFSProxy): | |||||||
|         except Exception, e: |         except Exception, e: | ||||||
|             raise ValidationError('Invalid image: %s' % e) |             raise ValidationError('Invalid image: %s' % e) | ||||||
|  |  | ||||||
|  |         # Progressive JPEG | ||||||
|  |         progressive = img.info.get('progressive') or False | ||||||
|  |  | ||||||
|  |         if (kwargs.get('progressive') and | ||||||
|  |                 isinstance(kwargs.get('progressive'), bool) and | ||||||
|  |                 img_format == 'JPEG'): | ||||||
|  |             progressive = True | ||||||
|  |         else: | ||||||
|  |             progressive = False | ||||||
|  |  | ||||||
|         if (field.size and (img.size[0] > field.size['width'] or |         if (field.size and (img.size[0] > field.size['width'] or | ||||||
|                             img.size[1] > field.size['height'])): |                             img.size[1] > field.size['height'])): | ||||||
|             size = field.size |             size = field.size | ||||||
| @@ -1339,14 +1349,14 @@ class ImageGridFsProxy(GridFSProxy): | |||||||
|                                     Image.ANTIALIAS) |                                     Image.ANTIALIAS) | ||||||
|  |  | ||||||
|         if thumbnail: |         if thumbnail: | ||||||
|             thumb_id = self._put_thumbnail(thumbnail, img_format) |             thumb_id = self._put_thumbnail(thumbnail, img_format, progressive) | ||||||
|         else: |         else: | ||||||
|             thumb_id = None |             thumb_id = None | ||||||
|  |  | ||||||
|         w, h = img.size |         w, h = img.size | ||||||
|  |  | ||||||
|         io = StringIO() |         io = StringIO() | ||||||
|         img.save(io, img_format) |         img.save(io, img_format, progressive=progressive) | ||||||
|         io.seek(0) |         io.seek(0) | ||||||
|  |  | ||||||
|         return super(ImageGridFsProxy, self).put(io, |         return super(ImageGridFsProxy, self).put(io, | ||||||
| @@ -1364,11 +1374,11 @@ class ImageGridFsProxy(GridFSProxy): | |||||||
|  |  | ||||||
|         return super(ImageGridFsProxy, self).delete(*args, **kwargs) |         return super(ImageGridFsProxy, self).delete(*args, **kwargs) | ||||||
|  |  | ||||||
|     def _put_thumbnail(self, thumbnail, format, **kwargs): |     def _put_thumbnail(self, thumbnail, format, progressive, **kwargs): | ||||||
|         w, h = thumbnail.size |         w, h = thumbnail.size | ||||||
|  |  | ||||||
|         io = StringIO() |         io = StringIO() | ||||||
|         thumbnail.save(io, format) |         thumbnail.save(io, format, progressive=progressive) | ||||||
|         io.seek(0) |         io.seek(0) | ||||||
|  |  | ||||||
|         return self.fs.put(io, width=w, |         return self.fs.put(io, width=w, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user