diff --git a/app.py b/app.py index c110acf..d0ffcc3 100644 --- a/app.py +++ b/app.py @@ -22,17 +22,23 @@ app = FastAPI(title="QL-1060N Stacked Barcode Printer") @lru_cache(maxsize=256) def make_code128(data: str) -> Image.Image: - writer_opts = { - "module_height": 15.0, - "module_width": 0.5, - "quiet_zone": 1.0, - "font_size": 10, - "text_distance": 1.0, - } - code = Code128( - data, writer=ImageWriter(), add_checksum=False, writer_options=writer_opts + # 1) Instantiate the barcode object (checksum auto-added for Code128) + code = Code128(data, writer=ImageWriter()) + + # 2) Render to a PIL.Image, passing any writer options and optional text override + pil_img = code.render( + writer_options={ + "module_height": 15.0, # bar height + "module_width": 0.5, # bar thickness + "quiet_zone": 1.0, # margin on each side + "font_size": 10, # text size + "text_distance": 1.0, # gap between bars and text + # you can also pass 'format': 'PNG' here if needed + }, + text=data, # explicitly draw your data string under the bars ) - pil_img = code.render(writer_opts) # returns RGB + + # 3) Convert to 1-bit for your Brother QL workflow return pil_img.convert("1")