Mike42\Escpos\EscposImage::toColumnFormat PHP Method

toColumnFormat() public method

Output the image in column format.
public toColumnFormat ( boolean $doubleDensity = false ) : string[]
$doubleDensity boolean True for double density (24px) lines, false for single-density (8px) lines.
return string[] an array, one item per line of output. All lines will be of equal size.
    public function toColumnFormat($doubleDensity = false)
    {
        // Just wraps implementations for caching and lazy loading
        if (isset($this->imgColumnData[$doubleDensity])) {
            /* Return cached value */
            return $this->imgColumnData[$doubleDensity];
        }
        $this->imgColumnData[$doubleDensity] = null;
        if ($this->allowOptimisations) {
            /* Use optimised code if allowed */
            $data = $this->getColumnFormatFromFile($this->filename, $doubleDensity);
            $this->imgColumnData[$doubleDensity] = $data;
        }
        if ($this->imgColumnData[$doubleDensity] === 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->imgColumnData[$doubleDensity] = $this->getColumnFormat($doubleDensity);
        }
        return $this->imgColumnData[$doubleDensity];
    }

Usage Example

Example #1
0
 /**
  * Print an image, using the older "bit image" command in column format.
  *
  * Should only be used if your printer does not support the graphics() or
  * bitImage() 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 bitImageColumnFormat(EscposImage $img, $size = Printer::IMG_DEFAULT)
 {
     $highDensityVertical = !(($size & self::IMG_DOUBLE_HEIGHT) == Printer::IMG_DOUBLE_HEIGHT);
     $highDensityHorizontal = !(($size & self::IMG_DOUBLE_WIDTH) == Printer::IMG_DOUBLE_WIDTH);
     // Experimental column format printing
     // This feature is not yet complete and may produce unpredictable results.
     $this->setLineSpacing(16);
     // 16-dot line spacing. This is the correct value on both TM-T20 and TM-U220
     // Header and density code (0, 1, 32, 33) re-used for every line
     $densityCode = ($highDensityHorizontal ? 1 : 0) + ($highDensityVertical ? 32 : 0);
     $colFormatData = $img->toColumnFormat($highDensityVertical);
     $header = Printer::dataHeader(array($img->getWidth()), true);
     foreach ($colFormatData as $line) {
         // Print each line, double density etc for printing are set here also
         $this->connector->write(self::ESC . "*" . chr($densityCode) . $header . $line);
         $this->feed();
         // sleep(0.1); // Reduces the amount of trouble that a TM-U220 has keeping up with large images
     }
     $this->setLineSpacing();
     // Revert to default line spacing
 }