mike42 / escpos-php

PHP library for printing to ESC/POS-compatible thermal and impact printers
Other
2.57k stars 862 forks source link

How to correctly load image on Laravel with BitImage? #1120

Open jumarjuaton opened 2 years ago

jumarjuaton commented 2 years ago

Hello,

I have used the bitimage code and was getting a Failed to load the image error.

  $logo = EscposImage::load(public_path() . "/custom/img/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);
  }
  $printer->cut();

Can I ask help on what is causing the error? When I dump the file, it was returning these params: Screenshot 2021-11-05 162942

Seems it is reading the file. Also what should be the standard resolution/size of the image? And should the image be dithered to work?

thealejandro commented 2 years ago

Hello,

I have used the bitimage code and was getting a Failed to load the image error.

  $logo = EscposImage::load(public_path() . "/custom/img/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);
  }
  $printer->cut();

Can I ask help on what is causing the error? When I dump the file, it was returning these params: Screenshot 2021-11-05 162942

Seems it is reading the file. Also what should be the standard resolution/size of the image? And should the image be dithered to work?

Add the library to use, as a final parameter, taking into account that by default it offers ['imagick', 'gd', 'native'].

When passing the parameter, it must be in an array, because it does a foreach to detect the method to use for image compression.

Add the library to use, as a final parameter, taking into account that by default it offers ['imagick', 'gd', 'native'].

When passing the parameter, it must be in an array, because it does a foreach to detect the method to use for image compression.

Here's an example of how you should do it: Before $logo = EscposImage::load(public_path() . "/custom/img/escpos-php.png", false); After

$logo = EscposImage::load(public_path() . "/custom/img/escpos-php.png", false, ['native']);