diff --git a/.gitignore b/.gitignore index ebfb5fa..8997141 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/inventree_phomemo/phomemo_label.py b/inventree_phomemo/phomemo_label.py index 5d99aa0..c69f9d5 100644 --- a/inventree_phomemo/phomemo_label.py +++ b/inventree_phomemo/phomemo_label.py @@ -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))