load() public static method

The sub-classes can be constructed directly if you know that you will have Imagick or GD on the print server.
public static load ( string $filename, string $allow_optimisations = true, array $preferred = ['imagick', 'gd', 'native'] ) : EscposImage
$filename string File to load from
$allow_optimisations string True to allow the fastest rendering shortcuts, false to force the library to read the image into an internal raster format and use PHP to render the image (slower but less fragile).
$preferred array Order to try to load libraries in- escpos-php supports pluggable image libraries. Items can be 'imagick', 'gd', 'native'.
return EscposImage
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();
Beispiel #2
0
        /* 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();
}
Beispiel #3
0
 public function testImageNotSupportedException()
 {
     $this->setExpectedException('InvalidArgumentException');
     $img = EscposImage::load('/dev/null', false, array());
 }
Beispiel #4
-1
require __DIR__ . '/../autoload.php';
use Mike42\Escpos\Printer;
use Mike42\Escpos\EscposImage;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
/* Fill in your own connector here */
$connector = new FilePrintConnector("php://stdout");
/* Information for the receipt */
$items = array(new item("Example item #1", "4.00"), new item("Another thing", "3.50"), new item("Something else", "1.00"), new item("A final item", "4.45"));
$subtotal = new item('Subtotal', '12.95');
$tax = new item('A local tax', '1.30');
$total = new item('Total', '14.25', true);
/* Date is kept the same for testing */
// $date = date('l jS \of F Y h:i:s A');
$date = "Monday 6th of April 2015 02:56:25 PM";
/* Start the printer */
$logo = EscposImage::load("resources/escpos-php.png", false);
$printer = new Printer($connector);
/* Print top logo */
$printer->setJustification(Printer::JUSTIFY_CENTER);
$printer->graphics($logo);
/* Name of shop */
$printer->selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
$printer->text("ExampleMart Ltd.\n");
$printer->selectPrintMode();
$printer->text("Shop No. 42.\n");
$printer->feed();
/* Title of receipt */
$printer->setEmphasis(true);
$printer->text("SALES INVOICE\n");
$printer->setEmphasis(false);
/* Items */
Beispiel #5
-2
<?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();
}