From 8bbbf7ceac820d94d633679f705890a05c830ed7 Mon Sep 17 00:00:00 2001 From: "B. Howell" Date: Tue, 9 May 2023 01:07:56 +0200 Subject: [PATCH] soft_barcode to render directly (#469) Rendering to /dev/null by a call to .write causes an error. Calling .render directly is simpler and fixes the error. Co-authored-by: Patrick Kanzler <4189642+patkan@users.noreply.github.com> --- src/escpos/escpos.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/escpos/escpos.py b/src/escpos/escpos.py index 3460fce..a5735e0 100644 --- a/src/escpos/escpos.py +++ b/src/escpos/escpos.py @@ -602,19 +602,16 @@ class Escpos(object): ) ) - # Render the barcode to a fake file + # Render the barcode barcode_class = barcode.get_barcode_class(barcode_type) my_code = barcode_class(data, writer=image_writer) - - with open(os.devnull, "wb") as nullfile: - my_code.write( - nullfile, - { - "module_height": module_height, - "module_width": module_width, - "text_distance": text_distance, - }, - ) + my_code.render( + writer_options={ + "module_height": module_height, + "module_width": module_width, + "text_distance": text_distance, + } + ) # Retrieve the Pillow image and print it image = my_code.writer._image