fix python-barcode usage
This commit is contained in:
parent
85b466f482
commit
33906be0cf
1 changed files with 16 additions and 10 deletions
26
app.py
26
app.py
|
|
@ -22,17 +22,23 @@ app = FastAPI(title="QL-1060N Stacked Barcode Printer")
|
||||||
|
|
||||||
@lru_cache(maxsize=256)
|
@lru_cache(maxsize=256)
|
||||||
def make_code128(data: str) -> Image.Image:
|
def make_code128(data: str) -> Image.Image:
|
||||||
writer_opts = {
|
# 1) Instantiate the barcode object (checksum auto-added for Code128)
|
||||||
"module_height": 15.0,
|
code = Code128(data, writer=ImageWriter())
|
||||||
"module_width": 0.5,
|
|
||||||
"quiet_zone": 1.0,
|
# 2) Render to a PIL.Image, passing any writer options and optional text override
|
||||||
"font_size": 10,
|
pil_img = code.render(
|
||||||
"text_distance": 1.0,
|
writer_options={
|
||||||
}
|
"module_height": 15.0, # bar height
|
||||||
code = Code128(
|
"module_width": 0.5, # bar thickness
|
||||||
data, writer=ImageWriter(), add_checksum=False, writer_options=writer_opts
|
"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")
|
return pil_img.convert("1")
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue