97-dithering.php 959B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. /*
  3. * Example of dithering used in EscposImage by default, if you have Imagick loaded.
  4. */
  5. require __DIR__ . '/../../vendor/autoload.php';
  6. use Mike42\Escpos\Printer;
  7. use Mike42\Escpos\EscposImage;
  8. use Mike42\Escpos\PrintConnectors\FilePrintConnector;
  9. $connector = new FilePrintConnector("/dev/usb/lp0");
  10. $printer = new Printer($connector);
  11. try {
  12. /* Load with optimisations enabled. If you have Imagick, this will get you
  13. a nicely dithered image, which prints very quickly
  14. */
  15. $img1 = EscposImage::load(__DIR__ . '/../resources/tulips.png');
  16. $printer -> bitImage($img1);
  17. /* Load with optimisations disabled, forcing the use of PHP to convert the
  18. pixels, which uses a threshold and is much slower.
  19. */
  20. $img2 = EscposImage::load(__DIR__ . '/../resources/tulips.png', false);
  21. $printer -> bitImage($img2);
  22. $printer -> cut();
  23. } finally {
  24. /* Always close the printer! */
  25. $printer -> close();
  26. }