Tune print quality defaults: density 2, font 30pt, threshold 160

- Default density to thick (2) for bolder output
- Default font size to 30pt for better readability
- Add draw.fontmode="1" to disable antialiasing for crisp 1-bit text
- Add ImageOps.autocontrast before thresholding images
- Update web GUI defaults to match CLI
This commit is contained in:
Hamza
2026-02-24 22:02:24 +01:00
parent c4ee77db62
commit a710328b5c
3 changed files with 13 additions and 11 deletions

View File

@@ -2,7 +2,7 @@
import logging
from PIL import Image, ImageDraw, ImageFont
from PIL import Image, ImageDraw, ImageFont, ImageOps
from fichero.printer import PRINTHEAD_PX
@@ -18,6 +18,7 @@ def prepare_image(img: Image.Image, max_rows: int = 240) -> Image.Image:
log.warning("Image height %dpx exceeds max %dpx, cropping bottom", new_h, max_rows)
new_h = max_rows
img = img.resize((PRINTHEAD_PX, new_h), Image.LANCZOS)
img = ImageOps.autocontrast(img, cutoff=1)
img = img.point(lambda x: 1 if x < 128 else 0, "1")
return img
@@ -31,12 +32,13 @@ def image_to_raster(img: Image.Image) -> bytes:
return img.tobytes()
def text_to_image(text: str, font_size: int = 24, label_height: int = 240) -> Image.Image:
"""Render text in landscape, then rotate 90 degrees for label printing."""
def text_to_image(text: str, font_size: int = 30, label_height: int = 240) -> Image.Image:
"""Render crisp 1-bit text, rotated 90 degrees for label printing."""
canvas_w = label_height
canvas_h = PRINTHEAD_PX
img = Image.new("L", (canvas_w, canvas_h), 255)
draw = ImageDraw.Draw(img)
draw.fontmode = "1" # disable antialiasing - pure 1-bit glyph rendering
font = ImageFont.load_default(size=font_size)