Import

Import API reference

Namespace: Com\Tecnick\Pdf\Image

class Import extends Output

Extends: Output

Source: src/Import.php:99

Types

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,
}

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,
}

Methods

add()

Add a new image.

public add(
    string $image,
    ?int $width = null,
    ?int $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): New width in pixels or null to keep the original value.
  • $height (?int): New height in pixels or null to keep the original value.
  • $ismask (bool): True if the image is a transparency mask.
  • $quality (int): Quality for JPEG files (0 = max compression; 100 = best quality, bigger file).
  • $defprint (bool): Indicate if the image is the default for printing when used as alternative image.
  • $altimgs (array<int,int>): Arrays of alternate image keys.

Returns: int: Image ID.

Throws:

Source: src/Import.php:180

getImageDataByKey()

Get an imported image by key.

public getImageDataByKey(string $key): ImageRawData

Parameters:

  • $key (string): Image key.

Returns: ImageRawData: Image raw data array.

Throws:

Source: src/Import.php:269

getImageDimensionsByKey()

Resolve the image dimensions for a cached image.

  • 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.
public getImageDimensionsByKey(
    string $key,
    int $width = 0,
    int $height = 0,
    bool $fit = false
): array{width: int, height: int}

Parameters:

  • $key (string): Image key.
  • $width (int): Target width in pixels (0 = unspecified).
  • $height (int): Target height in pixels (0 = unspecified).
  • $fit (bool): If true and both sides are specified, scale to fit within the bounding box preserving the aspect ratio.

Returns: array{width: int, height: int}: Image dimensions in pixels.

Throws:

Source: src/Import.php:299

getKey()

Get the Image key used for caching.

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): Width in pixels.
  • $height (int): Height in pixels.
  • $quality (int): Quality for JPEG files.
  • $ismask (bool): True if the image is a transparency mask.

Returns: string

Source: src/Import.php:212

Inherited members

From Output