diff options
| author | Fabien Meghazi <fme@openerp.com> | 2014-10-27 17:55:08 +0100 |
|---|---|---|
| committer | Fabien Meghazi <fme@openerp.com> | 2014-10-27 17:55:08 +0100 |
| commit | 3e07eaa308a4e0b352bea38c6331c62e53821f55 (patch) | |
| tree | 0f3e9764592032ae7426e45fa536989cd45a290f | |
| parent | abfe20bff6ce229b0e83f70ad83b83951fc421b1 (diff) | |
[FIX] Regression in image resize helper (Fixes #2529)
Commit 57ad514b makes the function preserve the aspect ration of the
original picture. Error of mine because the expected behavior was to
lose it for kanban view purpose.
For backward compatibility sake, this commit will keep the old behavior
by default.
| -rw-r--r-- | addons/website/models/website.py | 2 | ||||
| -rw-r--r-- | openerp/tools/image.py | 6 |
2 files changed, 5 insertions, 3 deletions
diff --git a/addons/website/models/website.py b/addons/website/models/website.py index 541a75aa3f0..25dc303f074 100644 --- a/addons/website/models/website.py +++ b/addons/website/models/website.py @@ -591,7 +591,7 @@ class website(osv.osv): response.data = data else: size = (max_w, max_h) - img = image_resize_and_sharpen(image, size) + img = image_resize_and_sharpen(image, size, preserve_aspect_ratio=True) image_save_for_web(img, response.stream, format=image.format) # invalidate content-length computed by make_conditional as # writing to response.stream does not do it (as of werkzeug 0.9.3) diff --git a/openerp/tools/image.py b/openerp/tools/image.py index aa110d7825e..0b02d27a631 100644 --- a/openerp/tools/image.py +++ b/openerp/tools/image.py @@ -96,19 +96,21 @@ def image_resize_image(base64_source, size=(1024, 1024), encoding='base64', file image.save(background_stream, filetype) return background_stream.getvalue().encode(encoding) -def image_resize_and_sharpen(image, size, factor=2.0): +def image_resize_and_sharpen(image, size, preserve_aspect_ratio=False, factor=2.0): """ Create a thumbnail by resizing while keeping ratio. A sharpen filter is applied for a better looking result. :param image: PIL.Image.Image() :param size: 2-tuple(width, height) + :param preserve_aspect_ratio: boolean (default: False) :param factor: Sharpen factor (default: 2.0) """ if image.mode != 'RGBA': image = image.convert('RGBA') image.thumbnail(size, Image.ANTIALIAS) - size = image.size + if preserve_aspect_ratio: + size = image.size sharpener = ImageEnhance.Sharpness(image) resized_image = sharpener.enhance(factor) # create a transparent image for background and paste the image on it |
