Mike42\Escpos\EscposImage::toRasterFormat PHP Method

toRasterFormat() public method

Output the image in raster (row) format. This can result in padding on the right of the image, if its width is not divisible by 8.
public toRasterFormat ( ) : string
return string The image in raster format.
    public function toRasterFormat()
    {
        // Just wraps implementations for caching & lazy loading
        if ($this->imgRasterData !== null) {
            /* Return cached value */
            return $this->imgRasterData;
        }
        if ($this->allowOptimisations) {
            /* Use optimised code if allowed */
            $this->imgRasterData = $this->getRasterFormatFromFile($this->filename);
        }
        if ($this->imgRasterData === null) {
            /* Load in full image and render the slow way if no faster implementation
               is available, or if we've been asked not to use it */
            if ($this->imgData === null) {
                $this->loadImageData($this->filename);
            }
            $this->imgRasterData = $this->getRasterFormat();
        }
        return $this->imgRasterData;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Print an image to the printer.
  * 
  * Size modifiers are:
  * - IMG_DEFAULT (leave image at original size)
  * - IMG_DOUBLE_WIDTH
  * - IMG_DOUBLE_HEIGHT
  * 
  * See the example/ folder for detailed examples.
  * 
  * The function bitImage() takes 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 Output size modifier for the image.
  */
 function graphics(EscposImage $img, $size = self::IMG_DEFAULT)
 {
     self::validateInteger($size, 0, 3, __FUNCTION__);
     $imgHeader = self::dataHeader(array($img->getWidth(), $img->getHeight()), true);
     $tone = '0';
     $colors = '1';
     $xm = ($size & self::IMG_DOUBLE_WIDTH) == self::IMG_DOUBLE_WIDTH ? chr(2) : chr(1);
     $ym = ($size & self::IMG_DOUBLE_HEIGHT) == self::IMG_DOUBLE_HEIGHT ? chr(2) : chr(1);
     $header = $tone . $xm . $ym . $colors . $imgHeader;
     $this->wrapperSendGraphicsData('0', 'p', $header . $img->toRasterFormat());
     $this->wrapperSendGraphicsData('0', '2');
 }