escimages
extracts raster images from binary ESC/POS files.
All non-graphical elements of the receipt are ignored, and a pair of files is written (in PBM and PNG format) for each image found in the source file.
This utility is included with escpos-tools. See the escpos-tools documentation for installation instructions.
Usage: escimages.php OPTIONS --file 'filename'
Required options:
-f, --file FILE The input file to read.
Output options:
-o, --output-dir DIRECTORY The directory to write output files to.
Output format:
Select one or more formats for output. If none is specified, then PNG is used.
--png Write output files in PNG format.
--pbm Write output files in PBM format.
Other options:
-h, --help Show this help
$ php escimages.php -f receipt-with-logo.bin
The raster image from the input receipt is extracted in PNG format:
The same binary data, when sent to a printer, renders as below:
$ cat receipt-with-logo.bin > /dev/usb/lp0
The input file used as an example here was generated by escpos-php, and is available here.
This utility will create raster images only. They can be printed back to a printer
via escpos-php
, or rendered to other formats with the ImageMagick convert
utility.
In some cases, drivers convert text to a series of images before printing. To recover
text from this type of receipt, the images from escimage
can be stacked and
sent through a suitable OCR tool.
For example, using tesseract
:
rm *.pbm
php escimages.php -f input.bin --pbm
convert -append *.pbm pbm:- | tesseract - -