Mike42\Escpos\Printer::graphics PHP Method

graphics() public method

Size modifiers are: - Printer::IMG_DEFAULT (leave image at original size) - Printer::IMG_DOUBLE_WIDTH - Printer::IMG_DOUBLE_HEIGHT See the example/ folder for detailed examples. The functions bitImage() and bitImageColumnFormat() take the same parameters, and can be used if your printer doesn't support the newer graphics commands.
public graphics ( EscposImage $img, integer $size = Printer::IMG_DEFAULT )
$img EscposImage The image to print.
$size integer Size modifier for the image. Must be either `Printer::IMG_DEFAULT` (default), or any combination of the `Printer::IMG_DOUBLE_HEIGHT` and `Printer::IMG_DOUBLE_WIDTH` flags.
    public function graphics(EscposImage $img, $size = Printer::IMG_DEFAULT)
    {
        self::validateInteger($size, 0, 3, __FUNCTION__);
        $rasterData = $img->toRasterFormat();
        $imgHeader = Printer::dataHeader(array($img->getWidth(), $img->getHeight()), true);
        $tone = '0';
        $colors = '1';
        $xm = ($size & self::IMG_DOUBLE_WIDTH) == Printer::IMG_DOUBLE_WIDTH ? chr(2) : chr(1);
        $ym = ($size & self::IMG_DOUBLE_HEIGHT) == Printer::IMG_DOUBLE_HEIGHT ? chr(2) : chr(1);
        $header = $tone . $xm . $ym . $colors . $imgHeader;
        $this->wrapperSendGraphicsData('0', 'p', $header . $rasterData);
        $this->wrapperSendGraphicsData('0', '2');
    }

Usage Example

Beispiel #1
1
<?php

/* Print-outs using the newer graphics 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->graphics($tux);
    $printer->text("Regular Tux.\n");
    $printer->feed();
    $printer->graphics($tux, Printer::IMG_DOUBLE_WIDTH);
    $printer->text("Wide Tux.\n");
    $printer->feed();
    $printer->graphics($tux, Printer::IMG_DOUBLE_HEIGHT);
    $printer->text("Tall Tux.\n");
    $printer->feed();
    $printer->graphics($tux, Printer::IMG_DOUBLE_WIDTH | Printer::IMG_DOUBLE_HEIGHT);
    $printer->text("Large Tux in correct proportion.\n");
    $printer->cut();
} catch (Exception $e) {
    /* Images not supported on your PHP, or image file not found */
    $printer->text($e->getMessage() . "\n");
}
$printer->close();
All Usage Examples Of Mike42\Escpos\Printer::graphics