get_image_base642attachment change format to jpeg

This commit is contained in:
Chill
2024-04-07 18:28:19 +08:00
parent 5145821227
commit 91dada2500
3 changed files with 15 additions and 9 deletions

View File

@@ -39,7 +39,7 @@
{
'name': "odooAi Common Util and Tools,欧度智能基础核心优化",
'version': '16.24.03.11',
'version': '16.24.04.07',
'author': 'odooai.cn',
'category': 'Base',
'website': 'https://www.odooai.cn',

View File

@@ -1,18 +1,19 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
from odoo.http import request
import requests
import base64
from io import BytesIO
import uuid
from PIL import Image
from datetime import date, datetime, time
import pytz
import logging
from odoo import models, fields, api, _
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT, DEFAULT_SERVER_DATETIME_FORMAT
from odoo.http import request
_logger = logging.getLogger(__name__)
# 常规的排除的fields
@@ -188,12 +189,17 @@ def get_image_base642attachment(data):
return None
try:
image_data = data.split(',')[1]
file_name = str(uuid.uuid4()) + '.png'
return image_data, file_name
img = Image.open(BytesIO(base64.b64decode(image_data)))
img = img.convert('RGB')
output = BytesIO()
img.save(output, format='JPEG')
file_name = str(uuid.uuid4()) + '.jpeg'
jpeg_data = output.getvalue()
jpeg_base64 = base64.b64encode(jpeg_data)
return jpeg_base64, file_name
except Exception as e:
return None, None
def get_ua_type():
ua = request.httprequest.headers.get('User-Agent')
# 临时用 agent 处理,后续要前端中正确处理或者都从后台来

View File

@@ -4,7 +4,7 @@
<h2 class="oe_slogan">odooAi Common Util and Tools</h2>
<h3 class="oe_slogan"> Network and media and base tools </h3>
<div class="oe_row">
<h3>Latest update: v16.24.03.11</h3>
<h3>Latest update: v16.24.04.07</h3>
<div class="row">
<img class="oe_demo oe_screenshot img img-fluid" style="max-height: 100%;" src="banner.png">
</div>