fix(label): Use buffer for image
This commit is contained in:
parent
b29acedffd
commit
cf7003aa9a
2 changed files with 7 additions and 3 deletions
|
@ -5,6 +5,7 @@ from django.core.validators import MaxValueValidator
|
|||
|
||||
# printer supportt
|
||||
import socket
|
||||
import io
|
||||
|
||||
# InvenTree plugin libs
|
||||
from plugin import InvenTreePlugin
|
||||
|
@ -56,14 +57,16 @@ class PhomemoLabelPlugin(LabelPrintingMixin, SettingsMixin, InvenTreePlugin):
|
|||
label_image = label_image.convert('L').point(fn, mode='1')
|
||||
|
||||
##### Convert to phomemo
|
||||
img_byte_arr = io.BytesIO()
|
||||
label_image.save(img_byte_arr, format='PNG')
|
||||
img_byte_arr = img_byte_arr.getvalue()
|
||||
|
||||
# Send the label to the printer
|
||||
try:
|
||||
print_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
print_socket.settimeout(5)
|
||||
print_socket.connect((ip_address, port))
|
||||
data = label_image.tobytes("PNG")
|
||||
print_socket.send(data)
|
||||
print_socket.send(img_byte_arr)
|
||||
print_socket.close()
|
||||
except Exception as error:
|
||||
raise ConnectionError('Error connecting to printer server: ' + str(error))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue