Skip to content

Commit

Permalink
[FIX] bug image extension
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieudelva committed Aug 14, 2024
1 parent b05efd5 commit 1c971a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 5 additions & 2 deletions zip_product_image/models/product.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Copyright 2024 Akretion
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import base64
from odoo import api, models
import base64
import imghdr

LIMIT = 500

Expand All @@ -29,4 +30,6 @@ def _product_image_data(self):
if self.image:
return (base64.b64encode(self.image.getvalue()), self.image.extension)
return (False, False)
return (self.image_1920 or False, '.jpg')
image_data = base64.b64decode(self.image_1920)
image_type = imghdr.what(None, h=image_data)
return (self.image_1920 or False, f'.{image_type}')
4 changes: 1 addition & 3 deletions zip_product_image/wizards/export_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ def _get_zip_product_images(self, products):
name = ""
for field in self._product_field_names():
name = name or prd[field]
zip_file.writestr(
f"{name}{extension}", img_data
)
zip_file.writestr(f"{name}.{extension}", img_data)
else:
logger.warning(f"Product {prd.display_name} has no image")
if zip_file.filelist:
Expand Down

0 comments on commit 1c971a7

Please sign in to comment.