From 9977c4eaa9aa6f47db8b33855fc4726b4a83bee7 Mon Sep 17 00:00:00 2001 From: Tanner Collin Date: Wed, 26 Nov 2025 04:18:52 +0000 Subject: [PATCH] Print a simple image --- main.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..53c5fc3 --- /dev/null +++ b/main.py @@ -0,0 +1,34 @@ +from escpos.printer import Usb +from PIL import Image, ImageEnhance + +VENDOR_ID = 0x0416 +PRODUCT_ID = 0x5011 + +# Initialize printer +p = Usb(VENDOR_ID, PRODUCT_ID, interface=0, in_ep=0x81, out_ep=0x03) + +# Load and convert image +PRINTER_WIDTH = 384 # Set to your printer's pixel width (common: 384 or 576) + +PRINTER_WIDTH = 384 # Adjust to your printer + +img = Image.open('robbie.jpg') + +# Resize first +wpercent = (PRINTER_WIDTH / float(img.size[0])) +hsize = int((float(img.size[1]) * float(wpercent))) +img = img.resize((PRINTER_WIDTH, hsize), Image.LANCZOS) + +# Optional: Enhance contrast +img = ImageEnhance.Contrast(img).enhance(2.0) + +# Optional: Sharpen +# img = ImageEnhance.Sharpness(img).enhance(2.0) + +# Convert with dithering +img = img.convert('1', dither=Image.FLOYDSTEINBERG) + +# Print image +p.image(img) +p.cut() +