Should only be used if your printer does not support the graphics() command.
See also bitImageColumnFormat().
<?php /* Example print-outs using the older bit image print command */ require __DIR__ . '/../autoload.php'; use Mike42\Escpos\Printer; use Mike42\Escpos\EscposImage; use Mike42\Escpos\PrintConnectors\FilePrintConnector; $connector = new FilePrintConnector("php://stdout"); $printer = new Printer($connector); try { $tux = EscposImage::load("resources/tux.png", false); $printer->text("These example images are printed with the older\nbit image print command. You should only use\n\$p -> bitImage() if \$p -> graphics() does not\nwork on your printer.\n\n"); $printer->bitImage($tux); $printer->text("Regular Tux (bit image).\n"); $printer->feed(); $printer->bitImage($tux, Printer::IMG_DOUBLE_WIDTH); $printer->text("Wide Tux (bit image).\n"); $printer->feed(); $printer->bitImage($tux, Printer::IMG_DOUBLE_HEIGHT); $printer->text("Tall Tux (bit image).\n"); $printer->feed(); $printer->bitImage($tux, Printer::IMG_DOUBLE_WIDTH | Printer::IMG_DOUBLE_HEIGHT); $printer->text("Large Tux in correct proportion (bit image).\n"); } catch (Exception $e) { /* Images not supported on your PHP, or image file not found */ $printer->text($e->getMessage() . "\n"); } $printer->cut(); $printer->close();
/* Read stdout */ $outputStr = stream_get_contents($fd[1]); fclose($fd[1]); /* Read stderr */ $errorStr = stream_get_contents($fd[2]); fclose($fd[2]); /* Finish up */ $retval = proc_close($process); if ($retval != 0) { throw new Exception("Command {$cmd} failed: {$outputStr} {$errorStr}"); } } else { throw new Exception("Command '{$cmd}' failed to start."); } /* Load up the image */ try { $img = EscposImage::load($dest); } catch (Exception $e) { unlink($dest); throw $e; } unlink($dest); /* Print it */ $printer->bitImage($img); // bitImage() seems to allow larger images than graphics() on the TM-T20. bitImageColumnFormat() is another option. $printer->cut(); } catch (Exception $e) { echo $e->getMessage(); } finally { $printer->close(); }
$logo = EscposImage::load("resources/escpos-php.png", false); $imgModes = array(Printer::IMG_DEFAULT, Printer::IMG_DOUBLE_WIDTH, Printer::IMG_DOUBLE_HEIGHT, Printer::IMG_DOUBLE_WIDTH | Printer::IMG_DOUBLE_HEIGHT); foreach ($imgModes as $mode) { $printer->graphics($logo, $mode); } } catch (Exception $e) { /* Images not supported on your PHP, or image file not found */ $printer->text($e->getMessage() . "\n"); } $printer->cut(); /* Bit image */ try { $logo = EscposImage::load("resources/escpos-php.png", false); $imgModes = array(Printer::IMG_DEFAULT, Printer::IMG_DOUBLE_WIDTH, Printer::IMG_DOUBLE_HEIGHT, Printer::IMG_DOUBLE_WIDTH | Printer::IMG_DOUBLE_HEIGHT); foreach ($imgModes as $mode) { $printer->bitImage($logo, $mode); } } catch (Exception $e) { /* Images not supported on your PHP, or image file not found */ $printer->text($e->getMessage() . "\n"); } $printer->cut(); /* QR Code - see also the more in-depth demo at qr-code.php */ $testStr = "Testing 123"; $models = array(Printer::QR_MODEL_1 => "QR Model 1", Printer::QR_MODEL_2 => "QR Model 2 (default)", Printer::QR_MICRO => "Micro QR code\n(not supported on all printers)"); foreach ($models as $model => $name) { $printer->qrCode($testStr, Printer::QR_ECLEVEL_L, 3, $model); $printer->text("{$name}\n"); $printer->feed(); } $printer->cut();
<?php /* * Example of dithering used in EscposImage by default, if you have Imagick loaded. */ require __DIR__ . '/../../autoload.php'; use Mike42\Escpos\Printer; use Mike42\Escpos\EscposImage; use Mike42\Escpos\PrintConnectors\FilePrintConnector; $connector = new FilePrintConnector("/dev/usb/lp0"); $printer = new Printer($connector); try { /* Load with optimisations enabled. If you have Imagick, this will get you a nicely dithered image, which prints very quickly */ $img1 = EscposImage::load(__DIR__ . '/../resources/tulips.png'); $printer->bitImage($img1); /* Load with optimisations disabled, forcing the use of PHP to convert the pixels, which uses a threshold and is much slower. */ $img2 = EscposImage::load(__DIR__ . '/../resources/tulips.png', false); $printer->bitImage($img2); $printer->cut(); } finally { /* Always close the printer! */ $printer->close(); }