HEX
Server: LiteSpeed
System: Linux s12873.lon1.stableserver.net 5.14.0-611.11.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Dec 3 09:47:37 EST 2025 x86_64
User: jairicem (1242)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: /home/jairicem/alfijiri.com/vendor/mike42/escpos-php/example/specific/97-dithering.php
<?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();
}