mirror of
https://github.com/guohuadeng/app-odoo.git
synced 2025-02-23 04:11:36 +02:00
get_image_base642attachment change format to jpeg
This commit is contained in:
@@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
{
|
{
|
||||||
'name': "odooAi Common Util and Tools,欧度智能基础核心优化",
|
'name': "odooAi Common Util and Tools,欧度智能基础核心优化",
|
||||||
'version': '16.24.03.11',
|
'version': '16.24.04.07',
|
||||||
'author': 'odooai.cn',
|
'author': 'odooai.cn',
|
||||||
'category': 'Base',
|
'category': 'Base',
|
||||||
'website': 'https://www.odooai.cn',
|
'website': 'https://www.odooai.cn',
|
||||||
|
|||||||
@@ -1,18 +1,19 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- 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 requests
|
||||||
import base64
|
import base64
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
import uuid
|
import uuid
|
||||||
|
from PIL import Image
|
||||||
from datetime import date, datetime, time
|
from datetime import date, datetime, time
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
import logging
|
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__)
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# 常规的排除的fields
|
# 常规的排除的fields
|
||||||
@@ -188,12 +189,17 @@ def get_image_base642attachment(data):
|
|||||||
return None
|
return None
|
||||||
try:
|
try:
|
||||||
image_data = data.split(',')[1]
|
image_data = data.split(',')[1]
|
||||||
file_name = str(uuid.uuid4()) + '.png'
|
img = Image.open(BytesIO(base64.b64decode(image_data)))
|
||||||
return image_data, file_name
|
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:
|
except Exception as e:
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
def get_ua_type():
|
def get_ua_type():
|
||||||
ua = request.httprequest.headers.get('User-Agent')
|
ua = request.httprequest.headers.get('User-Agent')
|
||||||
# 临时用 agent 处理,后续要前端中正确处理或者都从后台来
|
# 临时用 agent 处理,后续要前端中正确处理或者都从后台来
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<h2 class="oe_slogan">odooAi Common Util and Tools</h2>
|
<h2 class="oe_slogan">odooAi Common Util and Tools</h2>
|
||||||
<h3 class="oe_slogan"> Network and media and base tools </h3>
|
<h3 class="oe_slogan"> Network and media and base tools </h3>
|
||||||
<div class="oe_row">
|
<div class="oe_row">
|
||||||
<h3>Latest update: v16.24.03.11</h3>
|
<h3>Latest update: v16.24.04.07</h3>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<img class="oe_demo oe_screenshot img img-fluid" style="max-height: 100%;" src="banner.png">
|
<img class="oe_demo oe_screenshot img img-fluid" style="max-height: 100%;" src="banner.png">
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user