Table of contents
Namespace: Com\Tecnick\Pdf\Image
Extends: Output
File: Import.php line 99
Tags
- since: 2011-05-23
- category: Library
- author: Nicola Asuni info@tecnick.com
- copyright: 2011-2026 Nicola Asuni - Tecnick.com LTD
- license: https://www.gnu.org/copyleft/lesser.html GNU-LGPL v3 (see LICENSE)
- link: https://github.com/tecnickcom/tc-lib-pdf-image
- phpstan-type: ImageBaseData array{ ‘bits’: int, ‘channels’: int, ‘colspace’: string, ‘data’: string, ’exturl’: bool, ‘file’: string, ‘filter’: string, ‘height’: int, ‘icc’: string, ‘ismask’: bool, ‘key’: string, ‘mapto’: int, ’native’: bool, ‘obj’: int, ‘obj_alt’: int, ‘obj_icc’: int, ‘obj_pal’: int, ‘pal’: string, ‘parms’: string, ‘raw’: string, ‘recode’: bool, ‘recoded’: bool, ‘splitalpha’: bool, ’trns’: array<int, int>, ’type’: int, ‘width’: int, }
- phpstan-type: ImageRawData array{ ‘bits’: int, ‘channels’: int, ‘colspace’: string, ‘data’: string, ’exturl’: bool, ‘file’: string, ‘filter’: string, ‘height’: int, ‘icc’: string, ‘ismask’: bool, ‘key’: string, ‘mapto’: int, ‘mask’?: ImageBaseData, ’native’: bool, ‘obj’: int, ‘obj_alt’: int, ‘obj_icc’: int, ‘obj_pal’: int, ‘out’?: true, ‘pal’: string, ‘parms’: string, ‘plain’?: ImageBaseData, ‘raw’: string, ‘recode’: bool, ‘recoded’: bool, ‘splitalpha’: bool, ’trns’: array<int, int>, ’type’: int, ‘width’: int, }
- SuppressWarnings: (“PHPMD.ExcessiveClassLength”)
- SuppressWarnings: (“PHPMD.ExcessiveClassComplexity”)
Methods
__construct()
File: Output.php line 102
public __construct(float $kunit, Encrypt $encrypt, File $fileHelper[, bool $pdfa = false ][, bool $compress = true ][, ImageCacheInterface|null $imageCache = null ][, bool $notransparency = false ]) : mixed
Parameters
- $kunit : float: Unit of measure conversion ratio.
- $encrypt : Encrypt: Encrypt object.
- $fileHelper : File: File helper for image loading and writing.
- $pdfa : bool = false: True if we are in PDF/A mode.
- $compress : bool = true: Set to false to disable stream compression.
- $imageCache : ImageCacheInterface|null = null: External cache used to persist processed image data across instances and processes (null = disabled).
- $notransparency : bool = false: True to suppress the soft mask of an alpha image.
add()
File: Import.php line 180
public add(string $image[, int|null $width = null ][, int|null $height = null ][, bool $ismask = false ][, int $quality = 100 ][, bool $defprint = false ][, array<int, int> $altimgs = [] ]) : int
Parameters
- $image : string: Image file name, URL or a ‘@’ character followed by the image data string. To link an image without embedding it on the document, set an asterisk character before the URL (i.e.: ‘*http://www.example.com/image.jpg’).
- $width : int|null = null: New width in pixels or null to keep the original value.
- $height : int|null = null: New height in pixels or null to keep the original value.
- $ismask : bool = false: True if the image is a transparency mask.
- $quality : int = 100: Quality for JPEG files (0 = max compression; 100 = best quality, bigger file).
- $defprint : bool = false: Indicate if the image is the default for printing when used as alternative image.
- $altimgs : array<int, int> = []: Arrays of alternate image keys.
Tags
- throws: Exception If the image cannot be added.
- throws: Exception If reading image content fails.
Return values
int —
Image ID.
getImageDataByKey()
File: Import.php line 269
public getImageDataByKey(string $key) : ImageRawData
Parameters
- $key : string: Image key.
Tags
- throws: Exception If the key is not found.
Return values
ImageRawData —
Image raw data array.
getImageDimensionsByKey()
File: Import.php line 299
public getImageDimensionsByKey(string $key[, int $width = 0 ][, int $height = 0 ][, bool $fit = false ]) : array{width: int, height: int}
- If both $width and $height are zero, the original image dimensions are returned.
- If only one of $width and $height is greater than zero, the other is calculated preserving the original aspect ratio.
- If both are greater than zero, they are returned as-is, unless $fit is true, in which case the image is scaled to fit within the $width x $height bounding box preserving the original aspect ratio.
Parameters
- $key : string: Image key.
- $width : int = 0: Target width in pixels (0 = unspecified).
- $height : int = 0: Target height in pixels (0 = unspecified).
- $fit : bool = false: If true and both sides are specified, scale to fit within the bounding box preserving the aspect ratio.
Tags
- throws: Exception If the key is not found.
Return values
array{width: int, height: int} —
Image dimensions in pixels.
getKey()
File: Import.php line 212
public getKey(string $image[, int $width = 0 ][, int $height = 0 ][, int $quality = 100 ][, bool $ismask = false ]) : string
Parameters
- $image : string: Image file name or content.
- $width : int = 0: Width in pixels.
- $height : int = 0: Height in pixels.
- $quality : int = 100: Quality for JPEG files.
- $ismask : bool = false: True if the image is a transparency mask.
Return values
string
getObjectNumber()
File: Output.php line 115
public getObjectNumber() : int
Return values
int
getOutImagesBlock()
File: Output.php line 230
public getOutImagesBlock(int $pon) : string
Parameters
- $pon : int: Current PDF Object Number.
Tags
- throws: Exception If image object encryption fails.
Return values
string —
PDF code for the images block.
getSetImage()
File: Output.php line 188
public getSetImage(int $iid, float $xpos, float $ypos, float $width, float $height, float $pageheight) : string
Parameters
- $iid : int: Image ID.
- $xpos : float: Abscissa (X coordinate) of the upper-left Image corner in user units.
- $ypos : float: Ordinate (Y coordinate) of the upper-left Image corner in user units.
- $width : float: Image width in user units.
- $height : float: Image height in user units.
- $pageheight : float: Page height in user units.
Tags
- throws: Exception If the image ID is not found.
Return values
string —
Image PDF page content.
getXobjectDict()
File: Output.php line 362
public getXobjectDict() : string
Return values
string
getXobjectDictByKeys()
File: Output.php line 377
public getXobjectDictByKeys(array<string|int, int> $keys) : string
Parameters
- $keys : array<string|int, int>: Image IDs.
Return values
string
hasDeviceCmykImage()
File: Output.php line 132
public hasDeviceCmykImage() : bool
Return values
bool
hasDroppedAlpha()
File: Output.php line 124
public hasDroppedAlpha() : bool
Return values
bool
withFileHelper()
File: Output.php line 162
public withFileHelper(File $fileHelper, callable(): TResult $callback) : TResult
Parameters
- $fileHelper : File: Temporary file helper to use while the callback executes.
- $callback : callable(): TResult: Callback executed with the temporary file helper.
Tags
- template
Return values
TResult