escpos-php
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Mike42\Escpos\EscposImage Class Reference

This class deals with images in raster formats, and converts them into formats which are suitable for use on thermal receipt printers. More...

Inheritance diagram for Mike42\Escpos\EscposImage:
Inheritance graph
[legend]

Public Member Functions

 __construct ($filename=null, $allowOptimisations=true)
 Construct a new EscposImage. More...
 
 getHeight ()
 
 getHeightBytes ()
 
 getWidth ()
 
 getWidthBytes ()
 
 toRasterFormat ()
 Output the image in raster (row) format. More...
 
 toColumnFormat ($doubleDensity=false)
 Output the image in column format. More...
 

Static Public Member Functions

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...
 

Protected Member Functions

 loadImageData (string $filename=null)
 Load an image from disk. More...
 
 setImgData ($data)
 Set image data. More...
 
 setImgWidth ($width)
 Set image width. More...
 
 setImgHeight ($height)
 Set image height. More...
 
 getRasterFormatFromFile ($filename=null)
 
 getColumnFormatFromFile ($filename=null, $highDensityVertical=true)
 

Protected Attributes

 $imgHeight = 0
 height of the image.
 
 $imgWidth = 0
 width of the image
 

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:

Output formats:

Libraries:

Constructor & Destructor Documentation

◆ __construct()

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

Construct a new EscposImage.

Parameters
string$filenamePath to image filename, or null to create an empty image.
boolean$allowOptimisationsTrue (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

◆ getColumnFormatFromFile()

Mike42\Escpos\EscposImage::getColumnFormatFromFile (   $filename = null,
  $highDensityVertical = true 
)
protected
Parameters
string$filenameFilename to load from
boolean$highDensityVerticalTrue 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$filenameFilename 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$filenameFile to load from
bool$allowOptimisationsTrue 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$preferredOrder to try to load libraries in- escpos-php supports pluggable image libraries. Items can be 'imagick', 'gd', 'native'.
Exceptions
ExceptionWhere 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$filenameFilename to load from.

◆ setImgData()

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

Set image data.

Parameters
string$dataImage 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$heightheight of the image.

◆ setImgWidth()

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

Set image width.

Parameters
int$widthwidth of the image

◆ toColumnFormat()

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

Output the image in column format.

Parameters
boolean$doubleDensityTrue 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
ExceptionWhere 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: