PHP Класс 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.
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$imgHeight integer height of the image.
$imgWidth integer width of the image

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
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.

Приватные методы

Метод Описание
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.

Описание методов

__construct() публичный Метод

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 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)
Результат string[] | null Column format data as array, or NULL if optimised renderer isn't available in this implementation.

getHeight() публичный Метод

public getHeight ( ) : integer
Результат integer height of the image in pixels

getHeightBytes() публичный Метод

public getHeightBytes ( ) : integer
Результат integer Number of bytes to represent a row of this image

getRasterFormatFromFile() защищенный Метод

protected getRasterFormatFromFile ( string $filename = null ) : string | null
$filename string Filename to load from
Результат string | null Raster format data, or NULL if no optimised renderer is available in this implementation.

getWidth() публичный Метод

public getWidth ( ) : integer
Результат integer Width of the image

getWidthBytes() публичный Метод

public getWidthBytes ( ) : integer
Результат integer Number of bytes to represent a row of this image

isGdLoaded() публичный статический Метод

public static isGdLoaded ( ) : boolean
Результат boolean True if GD is loaded, false otherwise

isImagickLoaded() публичный статический Метод

public static isImagickLoaded ( ) : boolean
Результат boolean True if Imagick is loaded, false otherwise

load() публичный статический Метод

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'.
Результат EscposImage

loadImageData() защищенный Метод

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() защищенный Метод

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() защищенный Метод

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

setImgWidth() защищенный Метод

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

toColumnFormat() публичный Метод

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.
Результат string[] an array, one item per line of output. All lines will be of equal size.

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.
public toRasterFormat ( ) : string
Результат string The image in raster format.

Описание свойств

$imgHeight защищенное свойство

height of the image.
protected int $imgHeight
Результат integer

$imgWidth защищенное свойство

width of the image
protected int $imgWidth
Результат integer