mike42 / escpos-php

PHP library for printing to ESC/POS-compatible thermal and impact printers
Other
2.59k stars 863 forks source link

error when printing logo. #1283

Open AdrianII opened 1 year ago

AdrianII commented 1 year ago

I apologize in advance for any errors in writing this issue as English is not my native language and I rely on Google Translate.

The script provided here is wonderful, it has helped me print tickets in my SCADA projects by making a call from node js or node red to the script created with Apache, recently I experimented with QR and barcode printing and everything is fine, the problem comes When trying to print the company logo, it either prints an error or does not print anything at all, experiment with changing the image quality, changing the format in jpg, ico, bpm, png, try reading the POS commands manual the printer and comparing them with those managed by the script (which helped me in a previous project that did not let me cut the paper) but everything seems to be correct, the printer it uses is a BIXOLON SRP-F310II, below I attach a piece of the code From how I was handling it, the commented parts are other attempts, if I used EscposImage::load it gave me an error (using any format), and if I sent it directly it just doesn't print it.

` $nombreArchivo="recursos/logo.png"; $logo = EscposImage::load($nombreArchivo, false);////////

$printer->bitImage($imagen); //$imagen = EscposImage::load($nombreArchivo, true,['gd','native', 'imagick']);

//$printer->bitImage($imagen); //$printer->graphics($imagen); //$printer->graphics($imagen, Printer::IMG_DOUBLE_WIDTH); //$printer->graphics($imagen, Printer::IMG_DOUBLE_HEIGHT); //$printer->graphics($imagen, Printer::IMG_DOUBLE_WIDTH | Printer::IMG_DOUBLE_HEIGHT); `

and then the error that the previous code sends me

`
Warning: Undefined variable $imagen in C:\xampp\htdocs\imprimir_ticket_php-master\index.php on line 113

Fatal error: Uncaught TypeError: Mike42\Escpos\Printer::bitImage(): Argument #1 ($img) must be of type Mike42\Escpos\EscposImage, null given, called in C:\xampp\htdocs\imprimir_ticket_php-master\index.php on line 113 and defined in C:\xampp\htdocs\imprimir_ticket_php-master\src\Mike42\Escpos\Printer.php:457 Stack trace:

0 C:\xampp\htdocs\imprimir_ticket_php-master\index.php(113): Mike42\Escpos\Printer->bitImage(NULL)

1 {main}

thrown in C:\xampp\htdocs\imprimir_ticket_php-master\src\Mike42\Escpos\Printer.php on line 457

Notice: Print connector was not finalized. Did you forget to close the printer? in C:\xampp\htdocs\imprimir_ticket_php-master\src\Mike42\Escpos\PrintConnectors\WindowsPrintConnector.php on line 164
`

AdrianII commented 1 year ago

fixed bug:

It happened that the Mandala library called a file that was not in the package that I downloaded, specifically it is the image method of the GfxPhp library and I downloaded it separately by searching for it on Google and I only added the folder named GfxPhp in the Mike42 folder