escpos-php icon indicating copy to clipboard operation
escpos-php copied to clipboard

How to correctly load image on Laravel with BitImage?

Open jumarjuaton opened this issue 4 years ago • 1 comments
trafficstars

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?

jumarjuaton avatar Nov 05 '21 08:11 jumarjuaton

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']);

thealejandro avatar Jan 27 '22 07:01 thealejandro