PHP Class Mike42\Escpos\EscposImage

Copyright (c) 2014-2015 Michael Billington , incorporating modifications by: - Roni Saha - Gergely Radics - Warren Doyle Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 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.
Mostrar archivo Open project: mike42/escpos-php Class Usage Examples

Protected Properties

Property Type Description
$imgHeight integer height of the image.
$imgWidth integer width of the image

Public Methods

Method Description
__construct ( string $filename = null, boolean $allowOptimisations = true ) Construct a new EscposImage.
getHeight ( ) : integer
getHeightBytes ( ) : integer
getWidth ( ) : integer
getWidthBytes ( ) : integer
isGdLoaded ( ) : boolean
isImagickLoaded ( ) : boolean
load ( string $filename, string $allow_optimisations = true, array $preferred = ['imagick', 'gd', 'native'] ) : EscposImage This is a convinience method to load an image from file, auto-selecting an EscposImage implementation which uses an available library.
toColumnFormat ( boolean $doubleDensity = false ) : string[] Output the image in column format.
toRasterFormat ( ) : string 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.

Protected Methods

Method Description
getColumnFormatFromFile ( string $filename = null, boolean $highDensityVertical = true ) : string[] | null
getRasterFormatFromFile ( string $filename = null ) : string | null
loadImageData ( string $filename = null ) Load an image from disk. This default implementation always gives a zero-sized image.
setImgData ( string $data ) Set image data.
setImgHeight ( integer $height ) Set image height.
setImgWidth ( integer $width ) Set image width.

Private Methods

Method Description
getColumnFormat ( boolean $highDensity ) : string[] Get column fromat from loaded image pixels, line by line.
getColumnFormatLine ( string $lineNo, string $highDensity ) : null | string Output image in column format. Must be called once for each line of output.
getRasterFormat ( ) : string Get column fromat from loaded image pixels, line by line.

Method Details

__construct() public method

Construct a new EscposImage.
public __construct ( string $filename = null, boolean $allowOptimisations = true )
$filename string Path to image filename, or null to create an empty image.
$allowOptimisations boolean 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() protected method

protected getColumnFormatFromFile ( string $filename = null, boolean $highDensityVertical = true ) : string[] | null
$filename string Filename to load from
$highDensityVertical boolean True for high density output (24px lines), false for regular density (8px)
return string[] | null Column format data as array, or NULL if optimised renderer isn't available in this implementation.

getHeight() public method

public getHeight ( ) : integer
return integer height of the image in pixels

getHeightBytes() public method

public getHeightBytes ( ) : integer
return integer Number of bytes to represent a row of this image

getRasterFormatFromFile() protected method

protected getRasterFormatFromFile ( string $filename = null ) : string | null
$filename string Filename to load from
return string | null Raster format data, or NULL if no optimised renderer is available in this implementation.

getWidth() public method

public getWidth ( ) : integer
return integer Width of the image

getWidthBytes() public method

public getWidthBytes ( ) : integer
return integer Number of bytes to represent a row of this image

isGdLoaded() public static method

public static isGdLoaded ( ) : boolean
return boolean True if GD is loaded, false otherwise

isImagickLoaded() public static method

public static isImagickLoaded ( ) : boolean
return boolean True if Imagick is loaded, false otherwise

load() public static method

The sub-classes can be constructed directly if you know that you will have Imagick or GD on the print server.
public static load ( string $filename, string $allow_optimisations = true, array $preferred = ['imagick', 'gd', 'native'] ) : EscposImage
$filename string File to load from
$allow_optimisations string 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).
$preferred array Order to try to load libraries in- escpos-php supports pluggable image libraries. Items can be 'imagick', 'gd', 'native'.
return EscposImage

loadImageData() protected method

Load an image from disk. This default implementation always gives a zero-sized image.
protected loadImageData ( string $filename = null )
$filename string Filename to load from.

setImgData() protected method

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

setImgHeight() protected method

Set image height.
protected setImgHeight ( integer $height )
$height integer height of the image.

setImgWidth() protected method

Set image width.
protected setImgWidth ( integer $width )
$width integer width of the image

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.

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.

Property Details

$imgHeight protected_oe property

height of the image.
protected int $imgHeight
return integer

$imgWidth protected_oe property

width of the image
protected int $imgWidth
return integer