Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FW][FIX] base: fix autoresize and exclude gif #96848

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions odoo/addons/base/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def _compute_mimetype(self, values):

def _postprocess_contents(self, values):
ICP = self.env['ir.config_parameter'].sudo().get_param
supported_subtype = ICP('base.image_autoresize_extensions', 'png,jpeg,gif,bmp,tif').split(',')
supported_subtype = ICP('base.image_autoresize_extensions', 'png,jpeg,bmp,tiff').split(',')

mimetype = values['mimetype'] = self._compute_mimetype(values)
_type, _subtype = mimetype.split('/')
Expand All @@ -320,16 +320,15 @@ def _postprocess_contents(self, values):
img = ImageProcess(False, verify_resolution=False)
img.image = Image.open(io.BytesIO(values['raw']))
img.original_format = (img.image.format or '').upper()
fn_quality = img.image_quality
else: # datas
img = ImageProcess(values['datas'], verify_resolution=False)
fn_quality = img.image_base64

w, h = img.image.size
nw, nh = map(int, max_resolution.split('x'))
if w > nw or h > nh:
img.resize(nw, nh)
img = img.resize(nw, nh)
quality = int(ICP('base.image_autoresize_quality', 80))
fn_quality = img.image_quality if is_raw else img.image_base64
values[is_raw and 'raw' or 'datas'] = fn_quality(quality=quality)
except UserError as e:
# Catch error during test where we provide fake image
Expand Down
6 changes: 6 additions & 0 deletions odoo/addons/base/tests/test_ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ def test_10_image_autoresize(self):
attach.raw = img_bin
self.assertApproximately(attach.raw, fullsize)

# no resize of gif
self.env['ir.config_parameter'].set_param('base.image_autoresize_max_px', '0x0')
gif_bin = b'GIF89a\x01\x00\x01\x00\x00\xff\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x00;'
attach.raw = gif_bin
self.assertEqual(attach.raw, gif_bin)

def test_11_copy(self):
"""
Copying an attachment preserves the data
Expand Down