mike42 / escpos-php

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

bitImage() and graphics() Not Working #942

Open RYoder97 opened 4 years ago

RYoder97 commented 4 years ago

I have an Epson TM88III that was previously working fine. Now if I try to print images, the script seems to halt, and after about 10 seconds, the printer continuously feeds blank paper.

I realized that I didn't enable PHP GD. Enabled it. Same result :( Changed permissions to all images to 777 to be safe. Still nothing. :(

Here is what print_r for the EscposImage Object returns:

Mike42\Escpos\GdEscposImage Object
(
    [imgHeight:protected] => 0
    [imgWidth:protected] => 0
    [imgData:Mike42\Escpos\EscposImage:private] =>
    [imgColumnData:Mike42\Escpos\EscposImage:private] => Array
        (
        )

    [imgRasterData:Mike42\Escpos\EscposImage:private] =>
    [filename:Mike42\Escpos\EscposImage:private] => logo.png
    [allowOptimisations:Mike42\Escpos\EscposImage:private] =>
)
mike42 commented 4 years ago

The TM-T88III should understand these commands, but it's hard to know what's happening based on this info. Could you share a minimal PHP example showing how you are interacting with the library, an image file you are trying to print, and also tell us which version you are using?

As of escpos-php version 3.0, imagick or gd are used if they are present, but neither are actually required, because we include gfx-php as a dependency.

RYoder97 commented 4 years ago

Hi Mike. I'm using PHP version 7.3, below is a minimal example of code. No exceptions are thrown. I installed both imagick and gd. Library version is 3.0. Also, I forgot to mention that I am using a Raspberry Pi 4. To better describe it, running this script results in the terminal/process hanging, and about 10 seconds in the printer will continuously feed paper indefinitely it seems. Commenting out the $printer -> bitImage($logo); stops the program from hanging and it exits. If you add a text command with the bitImage function removed, it will print the text. With the bitImage not even text will print. Here is a copy of the image I am trying to print: https://imgur.com/a/v6Qqlbs

Edit: Also, here is a link to my phpinfo, hosted on the Pi itself; https://ryoder.ddns.net/phpinfo.php

try{
    $logo = EscposImage::load("logo.png");

    $connector = null;
        $connector = new FilePrintConnector("/dev/usb/lp0");

        $printer = new Printer($connector);
    $printer -> initialize();

    $printer -> bitImage($logo);

    $printer -> feed();
    $printer -> cut();

    $printer -> close();
}

catch(Exception $e){
    die($e);
}
RYoder97 commented 4 years ago

Mike, I wanted to let you know I just tried using Composer to remove v3.0 of your library and instead install v2.2. Still no image printing. I even installed mbstring (not that I think that has to do with images anyways).

It's very strange. A month or two ago it was working fine with my Pi 4. I'm wondering if it has to do with the new dependency, the gfx library.

RYoder97 commented 4 years ago

Just wanted to give an update. I copied and pasted the code from my above post verbatim, minus changing the FilePrintConnector to WindowsPrintConnector. It works fine on Windows, but not on the Pi. So it seems the Pi is an issue. Which is odd because the client should not matter really since PHP is PHP.