| escpos-php

- Main Page
- Related Pages
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Functions Variables Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Mike42\Escpos\EscposImage Class Reference
Inheritance diagram for Mike42\Escpos\EscposImage:
[legend]

## Public Member Functions
| __construct ($filename=null, $allowOptimisations=true)
| getHeight ()
| getHeightBytes ()
| getWidth ()
| getWidthBytes ()
| toRasterFormat ()
| toColumnFormat ($doubleDensity=false)

## Static Public Member Functions
static | isGdLoaded ()
static | isImagickLoaded ()
static | load ($filename, $allowOptimisations=true, array $preferred=['imagick', 'gd', 'native'])

## Protected Member Functions
| loadImageData ($filename=null)
| setImgData ($data)
| setImgWidth ($width)
| setImgHeight ($height)
| getRasterFormatFromFile ($filename=null)
| getColumnFormatFromFile ($filename=null, $highDensityVertical=true)

## Protected Attributes
| $imgHeight = 0
| $imgWidth = 0

## Detailed Description

This class deals with images in raster formats, and converts them into formats which are suitable for use on thermal receipt printers. Currently, only PNG images (in) and ESC/POS raster format (out) are implemeted.

Input formats:

- Currently, only PNG is supported.
- Other easily read raster formats (jpg, gif) will be added at a later date, as this is not complex.
- The BMP format can be directly read by some commands, but this has not yet been implemented.

Output formats:

- Currently, only ESC/POS raster format is supported
- ESC/POS 'column format' support is partially implemented, but is not yet used by Escpos.php library.
- Output as multiple rows of column format image is not yet in the works.

Libraries:

- Currently, php-gd is used to read the input. Support for imagemagick where gd is not installed is also not complex to add, and is a likely future feature.
- Support for native use of the BMP format is a goal, for maximum compatibility with target environments.

## Constructor & Destructor Documentation

Mike42\Escpos\EscposImage::__construct | ( |  | $filename = `null`,
|  |  | $allowOptimisations = `true`
| ) |  |

Construct a new EscposImage.

Parameters

  string | $filename | Path to image filename, or null to create an empty image.
  boolean | $allowOptimisations | True (default) to use any library-specific tricks to speed up rendering, false to force the image to be read in pixel-by-pixel, which is easier to unit test and more reproducible between systems, but slower.

## Member Function Documentation

Mike42\Escpos\EscposImage::getColumnFormatFromFile | ( |  | $filename = `null`,
|  |  | $highDensityVertical = `true`
| ) |  |
| protected

Parameters

  string | $filename | Filename to load from
  boolean | $highDensityVertical | True for high density output (24px lines), false for regular density (8px)

Returns
  string[]|NULL Column format data as array, or NULL if optimised renderer isn't available in this implementation.

Mike42\Escpos\EscposImage::getHeight | ( |  | ) |

Returns
  int height of the image in pixels

Mike42\Escpos\EscposImage::getHeightBytes | ( |  | ) |

Returns
  int Number of bytes to represent a row of this image

Mike42\Escpos\EscposImage::getRasterFormatFromFile | ( |  | $filename = `null` | ) |
| protected

Parameters

  string | $filename | Filename to load from

Returns
  string|NULL Raster format data, or NULL if no optimised renderer is available in this implementation.

Mike42\Escpos\EscposImage::getWidth | ( |  | ) |

Returns
  int Width of the image

Mike42\Escpos\EscposImage::getWidthBytes | ( |  | ) |

Returns
  int Number of bytes to represent a row of this image

static Mike42\Escpos\EscposImage::isGdLoaded | ( |  | ) |
| static

Returns
  boolean True if GD is loaded, false otherwise

static Mike42\Escpos\EscposImage::isImagickLoaded | ( |  | ) |
| static

Returns
  boolean True if Imagick is loaded, false otherwise

static Mike42\Escpos\EscposImage::load | ( |  | $filename,
|  |  | $allowOptimisations = `true`,
|  | array | $preferred = `['imagick'`,
|  | 'gd' | ,
|  | 'native'] |
| ) |  |
| static

This is a convinience method to load an image from file, auto-selecting an EscposImage implementation which uses an available library.

The sub-classes can be constructed directly if you know that you will have Imagick or GD on the print server.

Parameters

  string | $filename | File to load from
  bool | $allowOptimisations | True to allow the fastest rendering shortcuts, false to force the library to read the image into an internal raster format and use PHP to render the image (slower but less fragile).
  array | $preferred | Order to try to load libraries in- escpos-php supports pluggable image libraries. Items can be 'imagick', 'gd', 'native'.

Exceptions

  Exception | Where no suitable library could be found for the type of file being loaded.

Returns
  EscposImage

Mike42\Escpos\EscposImage::loadImageData | ( |  | $filename = `null` | ) |
| protected

Load an image from disk. This default implementation always gives a zero-sized image.

Parameters

  string | null | $filename | Filename to load from.

Mike42\Escpos\EscposImage::setImgData | ( |  | $data | ) |
| protected

Set image data.

Parameters

  string | $data | Image data to use, string of 1's (black) and 0's (white) in row-major order.

Mike42\Escpos\EscposImage::setImgHeight | ( |  | $height | ) |
| protected

Set image height.

Parameters

  int | $height | height of the image.

Mike42\Escpos\EscposImage::setImgWidth | ( |  | $width | ) |
| protected

Set image width.

Parameters

  int | $width | width of the image

Mike42\Escpos\EscposImage::toColumnFormat | ( |  | $doubleDensity = `false` | ) |

Output the image in column format.

Parameters

  boolean | $doubleDensity | True for double density (24px) lines, false for single-density (8px) lines.

Returns
  string[] an array, one item per line of output. All lines will be of equal size.

Mike42\Escpos\EscposImage::toRasterFormat | ( |  | ) |

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.

Exceptions

  Exception | Where the generated data is unsuitable for the printer (indicates a bug or oversized image).

Returns
  string The image in raster format.

## Member Data Documentation

int Mike42\Escpos\EscposImage::$imgHeight = 0
| protected

height of the image.

int Mike42\Escpos\EscposImage::$imgWidth = 0
| protected

width of the image

The documentation for this class was generated from the following file:

- C:/www/aplusnet/incahellas.com/public_html/lib/escpos-php-development/src/Mike42/Escpos/EscposImage.php