Commit c78dbeac35c4169b4dadf4ce89563727eebe7495
Commits[COMMIT BEGIN]commit c78dbeac35c4169b4dadf4ce89563727eebe7495 Author: 0x4248 <[email protected]> Date: Mon Feb 16 23:48:46 2026 +0000 sparkylab: escpos image tests init Me and my friend Sparky have been working on getting image printing working on our ESC/POS compatible printer. We have been testing with a Toshiba printer that supports ESC/POS and can print images. We have been able to get it working, but we have also encountered some issues along the way. Code is subject to change and may not even work on other printers. We are still learning about this hardware. Authored: sparkydadoggo <[email protected]> Co-Authored: 0x4248 <[email protected]> Reviewed by: 0x4248 <[email protected]> diff --git a/lab/sparkylab/receipt.py b/lab/sparkylab/receipt.py index f026d15..73d3e26 100644 --- a/lab/sparkylab/receipt.py +++ b/lab/sparkylab/receipt.py @@ -1,4 +1,28 @@ -#made with Sparky's own 2 paws with a little help from Claude AI +# SPDX-License-Identifier: GPL-3.0 +# ESC/POS Image experiment +# +# receipt.py +# A simple script to print text and images on an ESC/POS compatible printer. +# +# Authored: sparkydadoggo <[email protected]> +# Co-Authored: 0x4248 <[email protected]> +# Reviewed by: 0x4248 <[email protected]> +# +# TESTED HARDWARE: +# - TOSHIBA ???? (I dont know what the actual model is, there is so manty numbers on the printer but +# all look like serial numbers, has ESC/POS support, "images" as we saw and serial over standard 2.0 USB, RS232) +# +# COPYRIGHT NOTICE +# Copyright (C) 2025-2026 0x4248 and contributors +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the license is not changed. +# +# This software is free and open source. Licensed under the GNU general +# public license version 3.0 as published by the Free Software Foundation. +# +# NOTE: +# made with Sparky's own 2 paws + from PIL import Image from escpos import * p = printer.Usb(0x08a6, 0x003d, profile ="default") @@ -12,8 +36,19 @@ while True: p.text("\n") p.cut() elif usertext.lower() == 'image': - p.profile.profile_data['media']['width']['pixels'] = 576 # or 384 + # XXX: If the image size is wrong or too large, expect an entire roll of paper to be lost. + # You will get an output of "random characters" and the printer will just keep printing. We + # assume that its just the printer printing the raw data of the image, but we dont know for + # sure. + p.profile.profile_data['media']['width']['pixels'] = 576 # or 384, test at your own risk img = Image.open(input("Enter the path to the image you want to print: ")) + # HACK: This is the weirdest part of the code, but it works. The printer can only print + # images that are 576 pixels wide (or 384 for some models), so we need to resize the image + # to fit the printer's width while maintaining the aspect ratio. + # + # We really should figure out if there is a better way to do this e.g detecting the + # printer's width and resizing the image accordingly, but for now this is a simple solution + # that "should" work with most images. printer_width = 576 aspect_ratio = img.height / img.width new_height = int(printer_width * aspect_ratio)[COMMIT END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.