This class deals with images in raster formats, and converts them into formats which are suitable for use on thermal receipt printers.
More...
|
static | isGdLoaded () |
|
static | isImagickLoaded () |
|
static | load (string $filename, bool $allowOptimisations=true, array $preferred=['imagick', 'gd', 'native']) |
| This is a convinience method to load an image from file, auto-selecting an EscposImage implementation which uses an available library. More...
|
|
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.
◆ __construct()
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. |
◆ getColumnFormatFromFile()
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.
◆ getHeight()
Mike42\Escpos\EscposImage::getHeight |
( |
| ) |
|
- Returns
- int height of the image in pixels
◆ getHeightBytes()
Mike42\Escpos\EscposImage::getHeightBytes |
( |
| ) |
|
- Returns
- int Number of bytes to represent a row of this image
◆ getRasterFormatFromFile()
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.
◆ getWidth()
Mike42\Escpos\EscposImage::getWidth |
( |
| ) |
|
- Returns
- int Width of the image
◆ getWidthBytes()
Mike42\Escpos\EscposImage::getWidthBytes |
( |
| ) |
|
- Returns
- int Number of bytes to represent a row of this image
◆ isGdLoaded()
static Mike42\Escpos\EscposImage::isGdLoaded |
( |
| ) |
|
|
static |
- Returns
- boolean True if GD is loaded, false otherwise
◆ isImagickLoaded()
static Mike42\Escpos\EscposImage::isImagickLoaded |
( |
| ) |
|
|
static |
- Returns
- boolean True if Imagick is loaded, false otherwise
◆ load()
static Mike42\Escpos\EscposImage::load |
( |
string |
$filename, |
|
|
bool |
$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
◆ loadImageData()
Mike42\Escpos\EscposImage::loadImageData |
( |
string |
$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. |
◆ setImgData()
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. |
◆ setImgHeight()
Mike42\Escpos\EscposImage::setImgHeight |
( |
|
$height | ) |
|
|
protected |
Set image height.
- Parameters
-
int | $height | height of the image. |
◆ setImgWidth()
Mike42\Escpos\EscposImage::setImgWidth |
( |
|
$width | ) |
|
|
protected |
Set image width.
- Parameters
-
int | $width | width of the image |
◆ toColumnFormat()
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.
◆ toRasterFormat()
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.
The documentation for this class was generated from the following file:
- src/Mike42/Escpos/EscposImage.php