Mike42\Escpos\Printer::dataHeader PHP Method

dataHeader() private static method

Convert widths and heights to characters. Used before sending graphics to set the size.
private static dataHeader ( array $inputs, boolean $long = true ) : string
$inputs array
$long boolean True to use 4 bytes, false to use 2
return string
    private static function dataHeader(array $inputs, $long = true)
    {
        $outp = array();
        foreach ($inputs as $input) {
            if ($long) {
                $outp[] = Printer::intLowHigh($input, 2);
            } else {
                self::validateInteger($input, 0, 255, __FUNCTION__);
                $outp[] = chr($input);
            }
        }
        return implode("", $outp);
    }

Usage Example

Example #1
0
 /**
  * Print an image to the printer.
  *
  * Size modifiers are:
  * - Printer::IMG_DEFAULT (leave image at original size)
  * - Printer::IMG_DOUBLE_WIDTH
  * - Printer::IMG_DOUBLE_HEIGHT
  *
  * See the example/ folder for detailed examples.
  *
  * The functions bitImage() and bitImageColumnFormat() take the same
  * parameters, and can be used if your printer doesn't support the newer
  * graphics commands.
  *
  * @param EscposImage $img The image to print.
  * @param int $size Size modifier for the image. Must be either `Printer::IMG_DEFAULT`
  *  (default), or any combination of the `Printer::IMG_DOUBLE_HEIGHT` and
  *  `Printer::IMG_DOUBLE_WIDTH` flags.
  */
 public function graphics(EscposImage $img, $size = Printer::IMG_DEFAULT)
 {
     self::validateInteger($size, 0, 3, __FUNCTION__);
     $rasterData = $img->toRasterFormat();
     $imgHeader = Printer::dataHeader(array($img->getWidth(), $img->getHeight()), true);
     $tone = '0';
     $colors = '1';
     $xm = ($size & self::IMG_DOUBLE_WIDTH) == Printer::IMG_DOUBLE_WIDTH ? chr(2) : chr(1);
     $ym = ($size & self::IMG_DOUBLE_HEIGHT) == Printer::IMG_DOUBLE_HEIGHT ? chr(2) : chr(1);
     $header = $tone . $xm . $ym . $colors . $imgHeader;
     $this->wrapperSendGraphicsData('0', 'p', $header . $rasterData);
     $this->wrapperSendGraphicsData('0', '2');
 }