fix(label): Use buffer for image
This commit is contained in:
parent
b29acedffd
commit
cf7003aa9a
2 changed files with 7 additions and 3 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,7 +1,8 @@
|
|||
# Created by https://www.toptal.com/developers/gitignore/api/macos,python,visualstudiocode
|
||||
# Edit at https://www.toptal.com/developers/gitignore?templates=macos,python,visualstudiocode
|
||||
|
||||
test.png # File generated by test server
|
||||
# File generated by test server
|
||||
test.png
|
||||
|
||||
### macOS ###
|
||||
# General
|
||||
|
|
|
@ -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
Reference in a new issue