mirror of
https://github.com/OCA/report-print-send.git
synced 2025-02-16 07:11:31 +02:00
Added graphic image support
This commit is contained in:
@@ -3,8 +3,11 @@
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
import time
|
||||
import base64
|
||||
import datetime
|
||||
import io
|
||||
import logging
|
||||
from PIL import Image, ImageOps
|
||||
from odoo import api, exceptions, fields, models
|
||||
from odoo.tools.translate import _
|
||||
from odoo.tools.safe_eval import safe_eval
|
||||
@@ -117,6 +120,29 @@ class PrintingLabelZpl2(models.Model):
|
||||
zpl2.ARG_COLOR: component.color,
|
||||
zpl2.ARG_ROUNDING: component.rounding,
|
||||
})
|
||||
elif component.component_type == 'graphic':
|
||||
pil_image = Image.open(io.BytesIO(
|
||||
base64.b64decode(component.graphic_image or data)))
|
||||
if component.width and component.height:
|
||||
pil_image = pil_image.resize(
|
||||
(component.width, component.height))
|
||||
|
||||
# Invert the colors
|
||||
if component.reverse_print:
|
||||
pil_image = ImageOps.invert(pil_image)
|
||||
|
||||
# Rotation (PIL rotates counter clockwise)
|
||||
if component.orientation == zpl2.ORIENTATION_ROTATED:
|
||||
pil_image = pil_image.transpose(Image.ROTATE_270)
|
||||
elif component.orientation == zpl2.ORIENTATION_INVERTED:
|
||||
pil_image = pil_image.transpose(Image.ROTATE_180)
|
||||
elif component.orientation == zpl2.ORIENTATION_BOTTOM_UP:
|
||||
pil_image = pil_image.transpose(Image.ROTATE_90)
|
||||
|
||||
label_data.graphic_field(
|
||||
component_offset_x, component_offset_y,
|
||||
pil_image
|
||||
)
|
||||
elif component.component_type == 'circle':
|
||||
label_data.graphic_circle(
|
||||
component_offset_x, component_offset_y, {
|
||||
|
||||
Reference in New Issue
Block a user